|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-10-07 23:46 UTC] derick@php.net
[2005-10-10 04:09 UTC] nickj-phpbugs at nickj dot org
[2005-10-19 23:11 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 06:00:01 2025 UTC |
Description: ------------ Should strtotime() ignore the weekday for some inputs, rather than treat it as a modifier? Example code: ================================================= <?php print "Should the weekday be treated as part of the time, rather than a modifier?\n"; $input = "Friday July 1 2005 10:00:00 AM"; print "input: " . $input . "\n"; $tStamp = strtotime($input); print "date : " . date ("l F j Y H:i:s A", $tStamp) . "\n\n"; print "Should the weekday be treated as part of the time, rather than a modifier?\n"; $input = "10:00:00 AM Friday July 1 2005"; print "input: " . $input . "\n"; $tStamp = strtotime($input); print "date : " . date ("H:i:s A l F j Y", $tStamp) . "\n"; ?> ================================================= Actual output: ================================================== G:\PHP bugs\php5-win32-200507020230>php.exe ..\weekday-as-time-not-modifier\weekday-as-time-not-modifier.php Should the weekday be treated as part of the time, rather than a modifier? input: Friday July 1 2005 10:00:00 AM date : Friday July 8 2005 10:00:00 AM Should the weekday be treated as part of the time, rather than a modifier? input: 10:00:00 AM Friday July 1 2005 date : 00:00:00 AM Friday July 8 2005 G:\PHP bugs\php5-win32-200507020230> ================================================== What I thought the output would be: ================================================== G:\PHP bugs\php5-win32-200507020230>php.exe ..\weekday-as-time-not-modifier\weekday-as-time-not-modifier.php Should the weekday be treated as part of the time, rather than a modifier? input: Friday July 1 2005 10:00:00 AM date : Friday July 1 2005 10:00:00 AM Should the weekday be treated as part of the time, rather than a modifier? input: 10:00:00 AM Friday July 1 2005 date : 10:00:00 AM Friday July 1 2005 G:\PHP bugs\php5-win32-200507020230> ================================================== Or, to put it another way: strtotime("Friday July 1 2005 10:00:00 AM") gives the same results as strtotime("10:00:00 AM", strtotime("Friday", strtotime("July 1 2005"))), when I would expect it to be equivalent to strtotime("10:00:00 AM", strtotime("July 1 2005")). Note: I'm not sure what I would expect to happen if the weekday was the wrong day (e.g. "Monday July 1 2005 10:00:00 AM"). I think maybe the least surprising thing would be if the weekday was always ignored for these two formats (since it's redundant as it can be determined from the date anyway), same as if the input had been "July 1 2005 10:00:00 AM". And if someone really did then want to use the "Monday" modifier, they could just use strtotime("Monday", strtotime("July 1 2005 10:00:00 AM")) to achieve this.