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

Hi Monks I have a problem here.. I want to convert a date to epoch. My date format is yyyymmddhhmmss. I am trying it in strawberry Perl. Looking for your help.

Replies are listed 'Best First'.
Re: date to epoch
by Ratazong (Monsignor) on Nov 15, 2011 at 09:07 UTC
    If you use Date::Calc, you could use the function Mktime for this (after splitting your string, e.g. using a regex).
    $time = Mktime($year,$month,$day, $hour,$min,$sec);
      I am new to perl.. Could you please give me a sample code ?

        # assumption: yyyymmddhhmmss $date =~ /(....)(..)(..)(..)(..)(..)/; my $year = $1; my $month = $2; ... my $sec = $6;
        However consider using character-classes (e.g. \d for a digit) and checking if $date is really in in the expected format instead of this "quick and dirty" solution.
Re: date to epoch
by MidLifeXis (Monsignor) on Nov 15, 2011 at 13:38 UTC

    See also Time::Local. Depending on the time zone of your original timestamp, you may need to use timelocal or timegm.

    Many of the other date and time modules on CPAN can also help with this conversion.

    --MidLifeXis