Please take a look at the documentation for Date::Manip, as I suggested in my earlier post. You need the DateCalc function to calculate ($somedate + 1 day).

Regarding your code above, in your original post, it wasn't clear that you wanted to enter every date from tomorrow to 90 days from now. If that's the case, you need to create a new date object for each day:
#!/usr/bin/perl # get current Date from MySql use warnings; use strict; use Date::Manip; + my @city=("C","K","D"); my $j; for ($j=0;$j<3;$j++) { my $date= ParseDate("today"); + my $i; + # either start from 0, or use <= for ($i=1;$i<=90;$i++) { $date= DateCalc($date, "+ 1 day"); $date= UnixDate($date, '%Y-%m-%d'); print "Date: $date, city: $city[$j]\n"; } }
The reason you were only getting 267 records is because your inner loop only executed 89 times:
for ($i=1;$i<90;$i++)
You either need to initialize $i to 0 or change the conditional expression to $i <= 90.

If you'd like to speed up the code, you should reverse the loop structure, with the date calculation in the outer loop (so each date is only calculated once rather than three times). Also note that the code below uses Perl-style loops rather than C-style:
#!/usr/bin/perl # get current Date from MySql use warnings; use strict; use Date::Manip; + my @city=("C","K","D"); + my $date= ParseDate("today"); + # using a Perl-style (not C-style) loop helps prevent # the error seen in the earlier loop construct for my $i ( 1 .. 90 ) { $date= DateCalc($date, "+ 1 day"); $date= UnixDate($date, '%Y-%m-%d'); + for my $j ( 0 .. 2 ) { print "Date: $date, city: $city[$j]\n"; } }
Hope this helps,

--sacked

In reply to Re: Re: Re: Date::Manip Help by sacked
in thread Date::Manip Help by Agyeya

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.