Ahhh the joys of figuring out what the date is, or what yesterday was....
Anywho.. I like all the suggestions so far, but I have a little something to add. Your data is already in a database, so personally I think you should leverage the power of the database for you like so,
%num = (
Jan => '01', Feb => '02', Mar => '03', Apr => '04',
May => '05', Jun => '06', Jul => '07', Aug => '08',
Sep => '09', Oct => '10', Nov => '11', Dec => '12'
);
($day,$mth,$year) = (localtime)[3,4,5];
if ($mth =~ /Jan/) {
# If its jan we need last year to this year
$s_year = $year - 1;
$e_year = $year;
} else {
$s_year = $year;
$e_year = $year;
}
if ($day <= 14) {
# Get last half of last month
$s_day = '16';
$e_day = '01';
$s_month = $num{$last{$mth}};
$e_mth = $num{$mth};
} else {
# Get the beginning of this month
$s_day = '01';
$e_day = '15';
$s_month = $num{$mth};
$e_month = $num{$mth};
}
$query = 'SELECT * from newreleases ';
$query = 'WHERE rel_date >= "$s_year-$s_mth-$s_day" AND rel_date <= "$
+e_year-$e_mth-$s_day";'
I jumped through more hoops than I like there, and there is some redundancy, but I don't need an exact date range, as the DB will know how to compute it. Also I don't need to keep track of leap years, or other idioms like the last day of any particular month.
All the suggestions above where good, I just thought that there was a simpler way. I mean the DB has to be able to compare stuff right? I just say start here, and go till there.
/* And the Creator, against his better judgement, wrote man.c */
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.