I need to display output for two months.
- Current month
- Previous month
My current month does not start on the 1st of the month but rather delayed 2 or 3 weeks, which I do like this:
// gets current month
$currMonth = date('n',time());
$prevWeek = strtotime("-2 week");
// gets Month of previous week
$monthPrevWeek = date('n',$prevWeek);
$checkMonth = $currMonth;
// if this month is greater than last week's month number (i.e. last week was a different month), use last week's month to check events
if ($currMonth == 1) { //if January
$checkMonth = 12;
} else {
if ($currMonth > $monthPrevWeek) {
$checkMonth = $monthPrevWeek;
}
}
$current_month = date('F', strtotime($checkMonth . '/1'));
////// Logic to get stats based on the time of month <<--
//// Year logic -->>
$yearNow = date("Y");
if ($checkMonth == '1') {
$YearPastMonth = ($yearNow - 1);
} else {
$YearPastMonth = $yearNow;
}
//// Year logic <<--
So I need to write two quesries, for "current" and "previous" months. I do it like this:
// CURRENT MONTH
SELECT...
WHERE...
AND MONTH(issue_date) = ".$checkMonth."
AND YEAR(issue_date) = ".$YearPastMonth."
// PREVIOUS MONTH
SELECT...
WHERE...
AND MONTH(issue_date) = ".$prev_month_number."
AND YEAR(issue_date) = ".$YearPastMonth."
I guess I started over complicating when the year came to change. Say today is January 13 2007, so my "current month" should be December 2006 (-2 weeks), and my "previous month" should be November 2006.
But if today is January 15: "current month" should be January 2007, and "previous month" December 2006.
I'm deep in the woods at this point and desperately need help. I must keep the same var names as it's on the live site.