Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Syntactic Confectionery Delight
 
PerlMonks  

Converting a day or days to seconds

by Ms. T. (Novice)
on Sep 29, 2004 at 15:56 UTC ( [id://395118]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Ms. T. has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to figure out what module to use to convert a day or number of days to seconds. I have tired downloading the CPAN Module Conver::TimeUnits, but it is not working on my NT. Can anyone help? Thanks, Ms. T.

Replies are listed 'Best First'.
Re: Converting a day or days to seconds
by dragonchild (Archbishop) on Sep 29, 2004 at 16:01 UTC
    What's wrong with multiplying by 86400?

    If you need to have a module do it, take a look at DateTime, Date::Calc and Date::Manip.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: Converting a day or days to seconds
by TedPride (Priest) on Sep 29, 2004 at 19:34 UTC
    Yes, the calculation is simple if you're only working with days:
    $days = 2; # (or any other number) $seconds = $days * 24 * 60 * 60;
      I used the calculation, but only used $days = $seconds * 86400. This seemed to work - am I wrong? I am just starting out in Perl, so I am probably totally confused! Thanks, Ms. T.
Re: Converting a day or days to seconds
by graff (Chancellor) on Sep 29, 2004 at 20:49 UTC
    If you mean "convert a day ... to seconds since the epoch", you can try the Time::Local module, which I believe is part of the perl core distribution.

    If you don't know what "seconds since the epoch" refers to, then I'm simply guessing wrong about what your question really means, and you should just ignore me and pay attention to the previous replies.

    There are lots of CPAN modules in the "Date::" family, and some of them are pretty awe-inspiring (or overwhelming, depending on your nature). If you're doing arithmetic involving dates, you're bound to find a Date:: module that suits you. (But you can do quite a lot with just Time::Local, as well.)

      graff, Thanks for your input. I was not clear in my question. I was simply searching for the number of days * the number of seconds in a day. T.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://395118]
Approved by kutsu
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.