My application (calendar with some events) that works with dates and weeks fall down because of some interesting issue.
By getting date it should show up all the events that happened in the week of this date. By passing 2008-12-29 it shows first week of 2008, January instead of first week of 2009, as date('W', '2008-12-29') returns 01 and date('Y', '2008-12-29') returns 2008.
I solved it for a meanwhile with some if statement that is not best solution I think:
$date_to_show = '2008-12-29';
$week = date('W', $date_to_show);
$year = date('Y', $date_to_show);
if($week=='01' && $year==date('Y')) {
$year_for_sql = $year+1;
} else {
$year_for_sql=$year;
}
Where $date_to_show is let's say date that is passed to app and $year_for_sql is what is used in SQL query like: "..WHERE YEARWEEK(event_time,1)='".$year_for_sql.$week."'.."
Please help me to find better and more stable solution, if it is not issue of PHP.