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

I have 2 stupid questions on time and dates.
I have 185 Min
I need to convert that into HH::MM No seconds.
I also have a datetime in the format of 7/19/2005 4:50:44PM
I need to convert that to just the date.
Is there a module to do this, please forgive my total lack of information on this, I am moving all my PHP apps to perl.

Replies are listed 'Best First'.
Re: Stupid Time issues
by Nkuvu (Priest) on Jul 19, 2005 at 23:51 UTC
    Three hours five minutes (03::05 as per your note there) and 7/19/05. Shazam! Glad we could help.

    Cereally Seriously, the minutes:

    my $minutes = 185; my $hours = $minutes / 60; $minutes = $minutes % 60; printf "Minutes: %02d:%02d\n", $hours, $minutes;

    For the date you may want a regex or POSIX::strftime or maybe just fields from localtime. Where is the datetime coming from?

Re: Stupid Time issues
by gube (Parson) on Jul 20, 2005 at 00:41 UTC

    Hi,

    Please go through the Date::Calc. This type date and time problem can be easily solved.

Re: Stupid Time issues
by Codon (Friar) on Jul 20, 2005 at 00:00 UTC

    Very powerful, potentially overkill (depending on needs): Date::Manip.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.
Re: Stupid Time issues
by garrison (Scribe) on Jul 20, 2005 at 00:44 UTC
    A more literal interpretation:
    my $dateonly = ( split(' ', '7/19/2005 4:50:44PM') )[0]; print "$dateonly\n";
Re: Stupid Time issues
by ChrisR (Hermit) on Jul 20, 2005 at 02:18 UTC
    TMTOWTDI:
    ($date) = "7/19/2005 4:50:44PM" =~ /(\d+\/\d+\/\d+)/;
Re: Stupid Time issues
by szabgab (Priest) on Jul 20, 2005 at 09:40 UTC
    There is a large set of PHP functions implemented in Perl modules (see PHP) which might help in understanding how to move various pieces of PHP code to Perl.
Re: Stupid Time issues
by trammell (Priest) on Jul 20, 2005 at 15:26 UTC
    Perhaps Date::Parse would work. From the command line:
    % perl -MDate::Parse -le 'print scalar localtime(str2time("7/19/2005 4 +:50:44PM"))' Tue Jul 19 16:50:44 2005