|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-04-14 15:44 UTC] jmalan at ocurrance dot com
I have designed a scheduler for a call center which uses the work week of saturday through friday. If you use strtotime("last saturday") in the first week of april after the first saturday of april your strtotime will be off by one day. This happens in any year only during this time frame. To test it make sure you change your dates on your testing server. Quick Fix is $lastThursday = strtotime("last friday").
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 11:00:01 2025 UTC |
Found a better fix. Instead of using strtotime("last saturday"), try this: date("m/d/Y H:i:s",strtotime("-1 week saturday")); The timechange didn't seem to have any affect to strtotime this way.How is the syntax completely different? Those php examples are all covered by the GNU docs as well. The whole point of the function is that it understands many different formats. And if you specify the right timezone in works just fine, just as I said. Try this: $ts1 = mktime(12,0,0,4,5,2003); echo date("l H:i:s m/d/y",$ts1); echo "<br>\n"; $ts2 = strtotime("last saturday PST",$ts1); echo "<br>\n"; echo date("l H:i:s m/d/y",$ts2); $ts3 = strtotime("last saturday PDT",$ts1); echo "<br>\n"; echo date("l H:i:s m/d/y",$ts3); This outputs: Saturday 12:00:00 04/05/03 Saturday 00:00:00 03/29/03 Friday 23:00:00 03/28/03 exactly as expected. I see no bug here.Unfortunately that still does not answer my question. I know how to get around the problem but the problem still exists. date("m/d/Y H:i:s",strtotime("last saturday MST")) returns 04/04/2003 23:00:00 if the time is after 2 AM sunday morning the 6th of april. Try it, set your calendar to the 7th of april 2003.The bug database is not a support forum. It is for reporting bugs. There is nothing wrong with the strtotime() function. It is giving you exactly what you are asking it for. In this case last saturday in MST may not be the same day as last saturday in MDT since you switched from one to the other in between that. A simple way around it is to just add a timezone fuzz factor if you don't know which timezone you are working with. As in: strtotime("12:00:00 last saturday MST") and strtotime("12:00:00 last saturday MDT"); One will give you 11am, the other 12, but both will be Saturday. If you still have trouble understanding timezones, please ask any further questions on the php-general mailing list.