I'm writing a reporting tool that draws information out of a database. Each time the report is run, I will only need the new items that were added the half-month before the current.....let me explain. Say today is january 25, so I'd like to see all of the items in my DB added from Jan 1 thru Jan 15. If Today were Jan 9 I would want to report on the entries added from Dec 16 thru the last day of December. So if I'm in the last half of the month, I'd like to report on the first half, if I'm in the first half of the month, I'd like to report on the last half of last month.

I need these dates in YYYYMMDD format. ( TIMESTAMP(8) )

Here is what I have written so far, I tried to do it using Date::Time, but I'm not familliar with the module. I'm afraid that this code may have errors since I didn't use a CPAN module specific to the task. Do any of you monks see a better way of doing this, or do you see any shortcomings of this code?

sub newrelease { print " New Releases \n"; my $start_day; my $end_day; (my $day,my $month,my $year) = (localtime)[3,4,5]; if ($day > 15) { $start_day = sprintf("%04d%02d%02d", $year + 1900, $month + 1, 0); $end_day = sprintf("%04d%02d%02d", $year + 1900, $month + 1, 15) +; } if ($day <= 15) { $start_day = sprintf("%04d%02d%02d", $year + 1900, $month, 15); $end_day = sprintf("%04d%02d%02d", $year + 1900, $month , 31); } print "New Releases from $start_day to $end_day \n"; # pass datestamp off to my &sql sub outside of this block of code &sql("stamp > $start_day and stamp =< $end_day"); }
Thanks,

-Silent11

In reply to date span in YYYYMMDD by silent11

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.