note 93408 modified in function.strtotime by danbrown

From: Date: Sun, 09 Jan 2011 16:56:20 +0000
Subject: note 93408 modified in function.strtotime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175570@lists.php.net to get a copy of this message
It took me a while to notice that strtotime starts searching from just after midnight of the first day of the month. So, if the month starts on the day you search for, the first day of the search is actually the next occurrence of the day. In my case, when I look for first Tuesday of the current month, I need to include a check to see if the month starts on a Tuesday. <?php if (date("l", strtotime("$thisMonth $thisYear"))=='Tuesday') { echo "<p>This month starts on a Tuesday. Use \"$thisMonth $thisYear\" to check for first Tuesday.</p>\n"; } else { echo "<p>This month does not start on a Tuesday. Use \"first tuesday $thisMonth $thisYear\" to check for first Tuesday.</p>\n"; } ?> --was-- Adding to what Merlin at silvercircle dot org said, it took me a while to notice that strtotime starts searching from just after midnight of the first day of the month. So, if the month starts on the day you search for, the first day of the search is actually the next occurrence of the day. In my case, when I look for first Tuesday of the current month, I need to include a check to see if the month starts on a Tuesday. <?php if (date("l", strtotime("$thisMonth $thisYear"))=='Tuesday') { echo "<p>This month starts on a Tuesday. Use \"$thisMonth $thisYear\" to check for first Tuesday.</p>\n"; } else { echo "<p>This month does not start on a Tuesday. Use \"first tuesday $thisMonth $thisYear\" to check for first Tuesday.</p>\n"; } ?> http://php.net/manual/en/function.strtotime.php

« previous php.notes (#175570) next »