in reply to date span in YYYYMMDD
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.%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";'
|
|---|