Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 wandering the Monastery: (9)
As of 2014-11-26 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (162 votes), past polls