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!