I understand that this is a veery old post. I needed a function to help me create a range of dates starting a few days ago and ending at the current date. I played with different dates and I discovered that something wrong happens around October. The "date" is not incremented anymore after 20181028 or 20171029 or 20161030 and so on. However, after that fatidic date it works fine again.

See and example:

Last date 20110101 Bill date 20181205 Data 20110102 Last date 20110101 Bill date 20181205 Data 20110103 Last date 20110101 Bill date 20181205 Data 20110104 ..... Last date 20110101 Bill date 20181205 Data 20111026 Last date 20110101 Bill date 20181205 Data 20111027 Last date 20110101 Bill date 20181205 Data 20111028 Last date 20110101 Bill date 20181205 Data 20111029 Last date 20110101 Bill date 20181205 Data 20111030 Last date 20110101 Bill date 20181205 Data 20111030 Last date 20110101 Bill date 20181205 Data 20111030 Last date 20110101 Bill date 20181205 Data 20111030 ......
$last_date = <STDIN>; chomp $last_date; for (my $i = $last_date; $i <= $bill_date; $i = AddDate( $i, 1)) { push @letter_dates, $i; printf "Last date %s Bill date %s Data %s\n", $last_date, $bill_da +te, $i; } sub AddDate { my $date = $_[0]; my $x = $_[1]; # set this. my $day = 24*60*60; my $xdays = $x * $day; my @t = (localtime(str2time($date) + $xdays))[5,4,3]; $t[0] += 1900; # localtime returns years since 1900. $t[1] += 1; # localtime returns month in range 0..11. $return_date = sprintf "%04d%02d%02d", $t[0], $t[1], $t[2]; return $return_date; }

2018-12-06 Athanasius added paragraph and code tags


In reply to Re^2: Adding Days To YYYYMMDD Date Format by Anonymous Monk
in thread Adding Days To YYYYMMDD Date Format by Zoomie

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.