Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

date manipulation

by vivapl (Acolyte)
on Feb 04, 2004 at 21:53 UTC ( [id://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;
    Boris
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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others about the Monastery: (1)
As of 2024-04-24 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found