note 51608 modified in function.strtotime by danbrown

From: Date: Mon, 18 May 2009 02:30:08 +0000
Subject: note 51608 modified in function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155656@lists.php.net to get a copy of this message
While working on an employee schedule application I noticed an issue with using strtotime('last...'). I ran tests on each weekday for each week within a year and noticed inconsistencies while using: <?php date('m/d/Y', strtotime('last Wednesday', '2005-04-05')); ?> Most calculations of the 'last Wednesday' for each week calculated accordingly however I noticed a problem with several dates, one being '04/05/2005' (April 5th 2005). <?php date('m/d/Y', strtotime('last Wednesday', '2005-04-05')); ?> The above should have returned '03/30/2005'. Instead, it returned '03/29/2005'. I don't understand why the function is returning this value. Regardless, my solution: <?php date('m/d/Y', strtotime('-1 week' ,strtotime('Wednesday', '2005-04-05'))); ?> --was-- While working on an employee schedule application I noticed an issue with using strtotime('last...'). I ran tests on each weekday for each week within a year and noticed inconsistencies while using: date('m/d/Y', strtotime('last Wednesday', '2005-04-05')) Most calculations of the 'last Wednesday' for each week calculated accordingly however I noticed a problem with several dates, one being '04/05/2005' (April 5th 2005). date('m/d/Y', strtotime('last Wednesday', '2005-04-05')) The above should have returned '03/30/2005'. Instead, it returned '03/29/2005'. I don't understand why the function is returning this value. Regardless, my solution: date('m/d/Y', strtotime('-1 week' ,strtotime('Wednesday', '2005-04-05'))) http://php.net/manual/en/function.strtotime.php

« previous php.notes (#155656) next »