Scrat has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I have an epoch start-date (1135202400) and an epoch end-date (1188252000).
I'd like to loop through each day from start-date to end-date and perform an action for that day. Using a for loop, I tried to increment the number by 86400:
for (my $i=1135202400; $i <= 1188252000; $i+86400) { print ">$i<\n"; }
Which obviously didn't work and returned the message:
Useless use of addition (+) in void context at...Then I tried this:
Which returned:for (my $i=1135202400; $i <= 1188252000; $i++) { print ">$i<\n" unless ($i%86400); }
a value for each day, except for the first value which, if converted to date format, turns out to be the same day as that of the start-date value, just 2 hours later...>1135209600< >1135296000< >1135382400< >1135468800< >1135555200< >1135641600< >1135728000< >1135814400< >1135900800< >1135987200< ...
I just need to loop through each day, from the start-date to the end-date, and when I convert the value back to date format the time must be displayed as 00:00:00 for each day, and not 02:00:00. Preferably I'd like to loop only once through each day to return a value, and not 86400 times. Thanks for any input / advice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loop through epoch days
by jeanluca (Deacon) on Sep 27, 2007 at 10:36 UTC | |
by Scrat (Monk) on Sep 27, 2007 at 10:57 UTC | |
by perlfan (Parson) on Sep 27, 2007 at 13:46 UTC | |
|
Re: Loop through epoch days
by andreas1234567 (Vicar) on Sep 27, 2007 at 11:16 UTC | |
by Scrat (Monk) on Sep 27, 2007 at 12:06 UTC | |
|
Re: Loop through epoch days
by regexes (Hermit) on Sep 27, 2007 at 11:09 UTC |