Date::Manip using system libraries?

S

Sandman

I am experiencing oddities with my system.

How come this doesn't work:

select unix_timestamp("1925-01-01");
-> 0

But this does:

perl -e 'use Date::Manip; print UnixDate("1925-01-01", "%s");'
-> -1420074000

Don't they both use the systems built in support for date integer? As it is, I
can't make PHP or MySQL convert to unixtime earlier than 1970 which is due to
my system (linux redhat 8) not supporting it in some way. but why does
Date::Manip do it?

Actually, now when I test it, this also work:

perl -e 'use Date::Manip; print UnixDate("1800-01-01", "%s");'
-> -5364666000

Which most certainly is before any unixtime epoch regardless of os support...
Hmmm, what to do, what to do.
 
G

Gregory Toomey

Sandman said:
I am experiencing oddities with my system.

How come this doesn't work:

select unix_timestamp("1925-01-01");
-> 0

But this does:

perl -e 'use Date::Manip; print UnixDate("1925-01-01", "%s");'
-> -1420074000

Don't they both use the systems built in support for date integer?

Apparently not.
As it
is, I can't make PHP or MySQL convert to unixtime earlier than 1970 which
is due to my system (linux redhat 8) not supporting it in some way. but
why does Date::Manip do it?

Why does Perl work and the others not? Who knows. If you like Perl's answer
then use Perl's date functions, not mysql.

The mysql manual says nothing about dates before 1970
http://www.mysql.com/doc/en/Date_and_time_functions.html

Actually, now when I test it, this also work:

perl -e 'use Date::Manip; print UnixDate("1800-01-01", "%s");'
-> -5364666000

Which most certainly is before any unixtime epoch regardless of os
support... Hmmm, what to do, what to do.

What on earth are you trying to achieve? Work out the number of seconds
between two artitrary dates? I use mysql every day, use the standard mysql
date format and NEVER use linux epoch dates. The epoch starts in 1970 so
dates before 1970 presumably result in negative seconds.

Assuming this is not just an academic exercise, the Perl Date::Calc module
works perfectly with huge date ranges. mysql has an date_add function you
might want to explore.

gtoomey
 
B

Ben Morrow

Sandman said:
I am experiencing oddities with my system.

How come this doesn't work:

select unix_timestamp("1925-01-01");
-> 0

But this does:

perl -e 'use Date::Manip; print UnixDate("1925-01-01", "%s");'
-> -1420074000

Negative epoch times are not valid: you should not use them. That
Date::Manip returns them here rather than returning an error I would
consider a bug.

Use some other time format, such as the YYYY-MM-DD you started with.

Ben
 
S

Sandman

Gregory said:
What on earth are you trying to achieve?

I want a function to return the unix timestamp of a arbitary date - just like
above. My problem is that I wanted this in PHP, not in Perl. I noticed that I
could do it in Perl with Date::Manip and I sortof hoped that that meant I could
use it in PHP somehow as well. Buit as it seems, Manip isn't even using the
system support, which I suppose PHP is, so I won't be able to do it in PHP, or
MySQL.
Work out the number of
seconds between two artitrary dates? I use mysql every day, use the
standard mysql date format and NEVER use linux epoch dates. The epoch
starts in 1970 so dates before 1970 presumably result in negative
seconds.

Well, my reason for wanting the epoch timestamp is for a whole other biunch of
PHP functions that only use that.
 
S

Sandman

I am experiencing oddities with my system.

How come this doesn't work:

select unix_timestamp("1925-01-01");
-> 0

But this does:

perl -e 'use Date::Manip; print UnixDate("1925-01-01", "%s");'
-> -1420074000

Negative epoch times are not valid: you should not use them. That
Date::Manip returns them here rather than returning an error I would
consider a bug.[/QUOTE]

Why are you saying they aren't valid? They seem to work fine once I've used
perl to extract the timestamp:

perl -e 'printf "%s", 19+00(localtime(-1420074000))[5];'
-> 1925

and

select from_unixtime(-1420074000);
-> 1925-01-01 00:00:00
Use some other time format, such as the YYYY-MM-DD you started with.

Well, my problem is with PHP. I have a date - such as "1925-01-01", and I want
information about that date. Which weekday was it, which week, day of month,
month and so on. PHP has some really neat date function for this, but they all
take unix_timestamp as a argument. This is ok, since it also has functions to
create unix timestamp from the above date, or even "Last monday" or "+ four
days" or whatever.

But, the functions that CREATE the unix timestamps are limited by the epoch,
yet the functions that USE them are not.

For the moment, I am using a Perlscript that I call from PHP to do the
conversion to timestamp, so it's working right now, but I wanted to do it all
in PHP.
 
A

Anno Siegel

Ben Morrow said:
Negative epoch times are not valid: you should not use them. That
Date::Manip returns them here rather than returning an error I would
consider a bug.

I think that's going too far. Expressing times as the number of seconds
since (or to) 1970 is possible and legitimate for any time. That different
functions have different limitations doesn't mean we must stick to the
most restrictive set.

Anno
 
G

gnari

Anno Siegel said:
I think that's going too far. Expressing times as the number of seconds
since (or to) 1970 is possible and legitimate for any time. That different
functions have different limitations doesn't mean we must stick to the
most restrictive set.

specially in the case of a module like Date::Manip that deliberately goes
to great lengths to be able to deal with all kinds of possible and
impossible
date formats, and is by far the least restrictive of the date modules.

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top