Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to subtract date by 1 day

by ikegami (Patriarch)
on Dec 13, 2007 at 15:08 UTC ( [id://656836]=note: print w/replies, xml ) Need Help??


in reply to Re: How to subtract date by 1 day
in thread How to subtract date by 1 day

If by day, the OP means 24 hours, that's fine. If he just wants to move back the date one day without changing the time, your solution is wrong since not every day has 24*60*60 seconds. Use timegm+gmtime to do date manips.

use POSIX qw( strftime ); use Time::Local qw( timegm ); my ($d,$m,$y) = (localtime())[3,4,5]; print(strftime("%Y_%m_%d\n", gmtime(timegm(0,0,0,$d,$m,$y) - 24*60*60) ));

With time:

use POSIX qw( strftime ); use Time::Local qw( timegm ); my ($sec,$min,$hour,$d,$m,$y) = localtime(); ($d,$m,$y) = (gmtime(timegm(0,0,0,$d,$m,$y) - 24*60*60))[3,4,5]; print(strftime("%Y_%m_%d_%H_%M_%S\n", $sec,$min,$hour,$d,$m,$y));

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-12-09 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (53 votes). Check out past polls.