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

Is there a way to get the time() value by using a date? Such as this:

01/12/2008

Is there a way to get the time() value of that date(midnight or whatever does not matter)?

I have searched a few areas, but cannot find the answer, can you point me in the right direction?
I know I can do it by using something like this: my $_string = (time() + (60 * 60 * 24 * 365)); that would be 1 year, from what I remember of Perl.

However, I need to get a specific date's time() value. Not a specific number of days or something.

thx,
Richard

Replies are listed 'Best First'.
Re: time() question
by tachyon (Chancellor) on Nov 23, 2004 at 04:18 UTC

    The shortest module that does this is Time::Local. This conversion is basically all it does.

    use Time::Local; $time = timelocal($sec,$min,$hour,$mday,$mon,$year); $time = timegm($sec,$min,$hour,$mday,$mon,$year); my ( $mday, $mon, $year ) = split '/', "01/12/2008"; $mon -= 1; # Time::Local uses months 0..11 like gmtime() and localti +me(). my $epoch_time = timegm(1,0,0,$mday,$mon,$year); # 1 second past midni +ght

    cheers

    tachyon

Re: time() question
by steves (Curate) on Nov 23, 2004 at 04:08 UTC
      Plus: DateTime, Time::Piece, Time::Local. Each varies somewhat in capability; if you are going to do much date work, pick one (or more) and learn what it can do. Time::Local is the only one listed included with perl; all are on CPAN.