PHP strtotime() different results of monday this week

Stefan O. picture Stefan O. · Mar 9, 2011 · Viewed 11k times · Source

I have a problem getting the date of monday in the current week.

echo date('Y-m-d',strtotime('monday this week'));

When I'm running the above code on my local machine (PHP 5.3) it outputs correctly '2011-03-07', but the same code on my server (PHP 5.2) outputs '2011-03-14' (that's monday next week).

I've tried to run date('W') on both machines and I get the same result (10).

Edit: Any ideas how get this work correctly?

Thanks in advance.

Answer

woodo picture woodo · Feb 22, 2012

Use date('Y-m-d',strtotime(date('o-\\WW')));