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

Re: How to subtract date by 1 day

by andreas1234567 (Vicar)
on Dec 13, 2007 at 10:14 UTC ( [id://656790]=note: print w/replies, xml ) Need Help??


in reply to How to subtract date by 1 day

Using DateTime:
$ perl -l use strict; use warnings; use DateTime; my $str = '2007_12_13_04_49_15'; $str =~ /^(\d+)_(\d+)_(\d+)_(\d+)_(\d+)/; my $dt = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5 ); print $dt->ymd . ' ' . $dt->hms; $dt->add( days => -1 ); print $dt->ymd . ' ' . $dt->hms; __END__ 2007-12-13 04:49:00 2007-12-12 04:49:00
--
Andreas

Replies are listed 'Best First'.
Re^2: How to subtract date by 1 day
by ewhitt (Scribe) on Dec 13, 2007 at 10:22 UTC
    Thanks everyone for your input. 2008-01-01 seems to break things. Date::Simple returns 2007-00-01.
      Date::Simple (3.02) works for me (on Linux):
      use strict; use warnings; use Date::Simple qw(date); my $d = date("2008-01-01"); my $yesterday = $d - 1; print $yesterday; __END__ 2007-12-31
      Check the test reports and consider filing a bug report if the latest version doesn't work for you.
      --
      Andreas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found