Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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
Replies are listed 'Best First'.
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: (10)
As of 2015-07-29 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls