Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Date::Calc Alternative

by Jazz (Curate)
on Dec 30, 2001 at 08:03 UTC ( #135200=note: print w/replies, xml ) Need Help??

in reply to Date::Calc Module

I like Class::Date instead of Date::Calc for this kind of simple date math (where sql statements can't be used).

use Class::Date qw/ date localdate now /; my $cmpday = date( date( '2001-11-9' ) + '1M' + '20D' ); # add 1 month +, 20 days my $today = date( localdate( now ))->truncate; # truncate makes time +midnight. if ( $cmpday == $today ){ print "Today is $cmpday.\n"; } else { print +( Class::Date->new( $today ) - $cmpday )->day, " days away. +\n"; }

Date::Calc is definitely faster, so if you're needing lots of speedy date calcs, stick with Date::Calc. Docs for Class::Date is here.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://135200]
talexb finishes writing a Cranky Old Man post, and hopes it will be taken in the spirit intended. :)
[Corion]: We're happy to have you here, talexb!
[talexb]: Thanks. :)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2018-07-19 14:11 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (409 votes). Check out past polls.