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

The time function conveniently returns the number of seconds after the year 1900. What is the easiest and best way to determine the number of seconds elapsed after 1900 given a date and time? (ie February 10, 2006, 1:30pm)

2006-02-09 Retitled by Arunbear, as per Monastery guidelines
Original title: 'time'

  • Comment on Find number of epoch seconds given a date and time

Replies are listed 'Best First'.
Re: Find number of epoch seconds given a date and time
by duff (Parson) on Feb 09, 2006 at 22:55 UTC

    Actually it returns the number of seconds since 0000 Jan 1, 1970 GMT. There are various modules on CPAN that can parse date strings. Try Date::Parse or search for "Date" on search.cpan.org for others.

    If you really want "seconds since 1900", you'll probably have to use Date::Manip or something.

Re: Find number of epoch seconds given a date and time
by ikegami (Patriarch) on Feb 10, 2006 at 05:49 UTC

    Core module Time::Local will do the trick, if you have the date already parsed out.

    # If the date is in local time. use Time::Local qw( timelocal ); my $time = timelocal(0, 30, 13, 10, 2-1, 2006); # If the date is in GMT. use Time::Local qw( timegm ); my $time = timegm(0, 30, 13, 10, 2-1, 2006);