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

Re: Getting yesterday's date, and random dates in the past

by brian_d_foy (Abbot)
on Apr 02, 2005 at 02:42 UTC ( #444346=note: print w/ replies, xml ) Need Help??


in reply to Getting yesterday's date, and random dates in the past

The DateTime module (as well as other Date modules) can add or subtract arbitrary time values.

#!/usr/bin/perl use DateTime; my $today = DateTime->now->truncate( to => 'day' ); my $yesterday = $today->subtract( days => 1 ); print "Today is $today\nYesterday was $yesterday\n";
--
brian d foy <brian@stonehenge.com>


Comment on Re: Getting yesterday's date, and random dates in the past
Download Code
Re^2: Getting yesterday's date, and random dates in the past
by fglock (Vicar) on Apr 02, 2005 at 03:11 UTC

    even easier:

    my $today = DateTime->today;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://444346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2014-10-02 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (69 votes), past polls