I have a system that compares the fiscal year and current date with the same date range of the year. You can set the year and month to view, and it always compares the same date range with the year previous. I set it like this, if the current day is a leap day, it compares with the 28th last year, and if last year was a leap year, and today it is 28th, it compares with last year until the 29th. if you look at a month other than the current month, it is displayed until the last day of that month, otherwise until the current date.
It’s good that it’s working fine now, but now my employers don’t want it to be before the current date, when they want it to return to the date of yesterday. How can I do this, my main problems are whether today is the 1st day of the month, or what if today is the first day of a fiscal year.
Here is the code that I have now:
function create_YTD_XML() { global $month; global $year; $last_year = $year - 1; if($year == date('Y') && $month == date('m')) { $this_day = date('d'); } else { $this_day = date('t', mktime(0, 0, 0, $month, 1, $year)); // LAST DAY OF MONTH } if(is_leap_year($year) && $this_day == 29) { $last_day = 28; } else if(is_leap_year($last_year) && $this_day == 28) { $last_day = 29; } else { $last_day = $this_day; } if($month >= 2) { $this_year_start = $year; $last_year_start = $last_year; } else { $this_year_start = $year - 1; $last_year_start = $last_year - 1; } $this_ytd_start = $this_year_start.'-02-01'; $last_ytd_start = $last_year_start.'-02-01'; $this_ytd_end = $year.'-'.str_pad($month, 2, "0", STR_PAD_LEFT).'-'.$this_day; $last_ytd_end = $last_year.'-'.str_pad($month, 2, "0", STR_PAD_LEFT).'-'.$last_day; }
What would be the best solution?
Thanks!
source share