Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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

Replies are listed 'Best First'.
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;
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$/
Re: date manipulation
by vivapl (Acolyte) on Feb 04, 2004 at 22:08 UTC
    Thanks!, Worked just the way I was looking for!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://326609]
Approved by bart
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2018-01-20 00:25 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.