Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

date to unix timestamp

by saintex (Scribe)
on Nov 25, 2010 at 16:02 UTC ( [id://873671]=perlquestion: print w/replies, xml ) Need Help??

saintex has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I tried to convert
a Mysql date into a Unix timestamp.
For example:

The date is this one:
2010-08-31 16:12:41


So:


use Time::Local; timelocal(24,12,16,31,8,2010);

But I have this error:
Day '31' out of range 1..30 at ecc.

August had 31 days,
so I don't understand the error.
Do you have some suggestion?

Replies are listed 'Best First'.
Re: date to unix timestamp
by mjscott2702 (Pilgrim) on Nov 25, 2010 at 16:18 UTC
    From the perldoc:

    It is worth drawing particular attention to the expected ranges for the values provided. The value for the day of the month is the actual day (ie 1..31), while the month is the number of months since January (0..11). This is consistent with the values returned from "localtime()" and "gmtime()".

    So month 8 is actually September - which has only 30 days

      ok,
      thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://873671]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found