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:

for (my $i=1135202400; $i <= 1188252000; $i++) { print ">$i<\n" unless ($i%86400); }
Which returned:
>1135209600< >1135296000< >1135382400< >1135468800< >1135555200< >1135641600< >1135728000< >1135814400< >1135900800< >1135987200< ...
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...

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.


In reply to Loop through epoch days by Scrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.