note 7772 added to mktime
| From: | robert dot jackson at utoronto dot ca | Date: | Tue, 15 Aug 2000 02:59:38 +0000 |
| Subject: | note 7772 added to mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-1873@lists.php.net to get a copy of this message | ||
I had to make a MySQL query for a given week (i.e. SELECT...WHERE date>='$last_sunday'
AND date<='$next_saturday').
The php code I came up with is illustrated by:
$yr="2000";
$mnth="03";
$dy="02";
echo "base date: ".$yr."-".$mnth."-".$dy."<br>";
echo "last sunday: ".date("Y-m-d",
mktime(0,0,0,$mnth,$dy-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."<br>";
echo "next saturday: ".date("Y-m-d",
mktime(0,0,0,$mnth,$dy+6-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."<br>";
This seems to work within a month, across months (including leap years), and across years.
http://www.php.net/manual/function.mktime.php