### date manipulation

by vivapl (Acolyte)
 on Feb 04, 2004 at 21:53 UTC 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;
Boris
Re: date manipulation
by Abigail-II (Bishop) on Feb 04, 2004 at 22:34 UTC
```use Date::Calc;
for 98% of the cases.
```use Date::Manip;
for the rest.

Abigail

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;
# 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!

Create A New User
Node Status?
node history
Node Type: perlquestion [id://326609]
Approved by bart
help
Chatterbox?
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
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (226 votes). Check out past polls.

Notices?