Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
[ambrus]: "could evacuate to open schoolyard and then call or go back to school" => wait what? like power cycling the school building by removing all the kids and then reentering them? how would that fix the problems?
[ambrus]: https://www.xkcd. com/723/ is relevant about earthquakes and phones
[ambrus]: must be this earthquake
[ambrus]: (It's convenient that I live in a place with no earthquakes or hurricanes. One less bad thing to look out for.)

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-01-18 12:40 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (161 votes). Check out past polls.