Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to subtract date by 1 day

by narainhere (Monk)
on Dec 13, 2007 at 10:04 UTC ( [id://656786]=note: print w/replies, xml ) Need Help??


in reply to How to subtract date by 1 day

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: How to subtract date by 1 day
by andreas1234567 (Vicar) on Dec 13, 2007 at 10:20 UTC
    That's fine until you get to the first day of the month:
    $ perl -l use strict; use warnings; my $db_name="2007_12_01_04_49_15"; my @date=split /_/,$db_name; $date[2]=$date[2]-1; $db_name=join '_',@date; print $db_name; __END__ 2007_12_0_04_49_15
    Date and time calculations (e.g. month changes, leap years, timezones) are surprisingly difficult to get right. Don't reinvent the wheel. Use an existing module from .
    --
    Andreas
Re^2: How to subtract date by 1 day
by johngg (Canon) on Dec 13, 2007 at 10:26 UTC
    Errr ... what happens when it is the first of the month? Perhaps you'd be better off looking at the timelocal function of Time::Local and localtime, converting to an epoch value, decrementing by 86400 then converting back.

    Cheers,

    JohnGG

Re^2: How to subtract date by 1 day
by prasadbabu (Prior) on Dec 13, 2007 at 10:21 UTC

    narainhere,

    What will happen if the day is 1st day of any month?
    So you have to check the condition for month and year also.

    Prasad

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found