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.
Use
date('Y-m-d',strtotime(date('o-\\WW')));
Not that I've seen exactly this problem, but I've seen ones very similar. strtotime seems to change behaviour between different versions of PHP, and barring the simple operations (eg. '+1 week'), it's difficult to guarantee that functionality will remain the same.
If you're not able to upgrade to 5.3, which as correctly pointed out does seem to be an improvement, all I can recommend, is playing with some permutations. It's often possible to get the right answer out of older versions of strtotime by rephrasing the question. Examples might include ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With