Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to get after 4 and 5 days date from today date

by fisher (Priest)
on Feb 15, 2011 at 15:38 UTC ( #888275=note: print w/replies, xml ) Need Help??


in reply to How to get after 4 and 5 days date from today date

sleep (5*24*60*60); my $after5date = localtime(time); print $after5date; sleep (4*24*60*60); my $after4days = localtime(time); print $after4days;
NB: sorry, this is a joke

Replies are listed 'Best First'.
Re^2: How to get after 4 and 5 days date from today date
by ikegami (Pope) on Feb 15, 2011 at 16:11 UTC

    Not all days have 24 hours. Fix below. This will also give you the answer up to 23.5 hours sooner.

    use POSIX qw( strftime ); sub next_day { my $start_d = (localtime)[3]; for (;;) { sleep(30*60); my $d = (localtime)[3]; return if $d != $start_d; } } next_day() for 1..5; print strftime("%Y-%m-%d\n", localtime()); next_day() for 1..4; print strftime("%Y-%m-%d\n", localtime());

    Suffers from a race-condition that manifests itself if the loops is started very shortly before midnight.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2020-12-06 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (65 votes). Check out past polls.

    Notices?