Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 ( [id://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>

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://444346]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-03-19 02:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found