Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

date manipulation

by vivapl (Acolyte)
on Feb 04, 2004 at 21:53 UTC ( #326609=perlquestion: print w/ replies, xml ) Need Help??
vivapl has asked for the wisdom of the Perl Monks concerning the following question:

In need of wisdom!

Need advise on how to calculate a new date. Eg: I need to retrieve tomorrows date or after.

Currently I'm plating with  localtime but not getting anywhere.

My ultimate goal is to pass the function number of days and be able to get the date ahead by that number

Any help would be greatly appreciated

Comment on date manipulation
Download Code
Re: date manipulation
by borisz (Canon) on Feb 04, 2004 at 22:03 UTC
    my $date_as_string = localtime(time() + $days * 24*60*60 ); print $date_as_string;
    Boris
Re: date manipulation
by vivapl (Acolyte) on Feb 04, 2004 at 22:08 UTC
    Thanks!, Worked just the way I was looking for!
Re: date manipulation
by Abigail-II (Bishop) on Feb 04, 2004 at 22:34 UTC
      Yeah. What Abigail said. Doing simple math on dates works ok most of the time... until the day comes when "the next day at this time" isn't 24 hours away (think daylight savings time.) That sort of thing will bite you one day... much better to rely on a module to remember that stuff for you.

      Gary Blackburn
      Trained Killer

Re: date manipulation
by jonadab (Parson) on Feb 05, 2004 at 05:16 UTC
    use DateTime; sub dateahead { my ($daystoadd) = @_; my $dt = DateTime->now()->add( days => $daystoadd); # What form do you want the result returned in? return $dt->date(); # This, perhaps? return $dt; # Or a DateTime object maybe? }

    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://326609]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-10-20 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (72 votes), past polls