Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 pondering the Monastery: (4)
As of 2015-05-30 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (593 votes), past polls