Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

date conversion

by monskie (Initiate)
on Dec 05, 2006 at 09:02 UTC ( [id://587822]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: date conversion
by davorg (Chancellor) on Dec 05, 2006 at 09:17 UTC

    The easy way would be to use a module like Date::Parse.

    But if you don't have that module installed and don't want to install it, then you can split the string into its constituent parts and use timelocal (or timegm) from the standard module Time::Local.

    But I'm not really sure how a date can be more or less than 14 hours. A date is just a point in time. You can't compare dates with durations.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      He probably meant "older", not "greater". In that case, he'd compare the difference between the output of str2time or timelocal and the output of time against 14*60*60 (14 hours in seconds).

Re: date conversion
by mickeyn (Priest) on Dec 05, 2006 at 09:34 UTC
    str2time (use Date::Parse) will do what you want.

    HTH,
    Mickey

Re: date conversion
by ww (Archbishop) on Dec 05, 2006 at 16:31 UTC
          ... and if you're wondering why your OFT-ANSWERED QUESTION has garnered so many downvotes, I would guess that many (like mine) were for your apparent failure to read the introductory material about the Monastery (links will be found in the right sidebar, in all likelihood) or even start with such advice as can be found in How do I post a question effectively?.

    On the other hand, don't worry about the downvotes. And Welcome!

    But do make your visits more productive by learning about and using the resources here. For just one example, entering the words convert and time in the search box (in the *usually* blue "Perl Monks" title-bar near the top of the page) would have shown you links to some of the many times your question has been asked and answered in the past.

Re: date conversion
by madbombX (Hermit) on Dec 05, 2006 at 13:18 UTC
    Depending on what you want to do with the date and how you have access to it, you may also want to check out the CPAN modules Date::Manip and Date::Calc.
Re: date conversion
by ptum (Priest) on Dec 05, 2006 at 15:28 UTC

    Sometimes it is worth your while to consider why you are converting in the first place.

    That string looks a lot like a scalar representation of localtime ... if you want seconds since the epoch started for a numerical comparison, better to use time in the first place, perhaps as in this (untested) snippet:

    use strict; use warnings; my $eval_time = get_time_of_thing_i_am_checking(); my $now = time(); my $some_interval = 60 * 60 * 14; if (($now - $eval_time) > $some_interval) { # do stuff } else { print "Not enough time has elapsed. Go fish.\n"; }
Re: date conversion
by xdbd063 (Friar) on Dec 05, 2006 at 16:33 UTC

    I have to agree with davorg on this one. "A date is just a point in time." You are asking about one specific second - Thursday, May 18th, 2006 at 17:31:05. Did you maybe want to take the time past midnight and convert it into seconds, or past a specific date and time?

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://587822]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-25 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found