note 7773 added to date

From: Date: Tue, 15 Aug 2000 03:02:38 +0000
Subject: note 7773 added to date
Groups: php.notes 
Request: Send a blank email to php-notes+get-1874@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."&lt;br>"; echo "last sunday: ".date("Y-m-d", mktime(0,0,0,$mnth,$dy-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."&lt;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))."&lt;br>"; This seems to work within a month, across months (including leap years), and across years. http://www.php.net/manual/function.date.php

« previous php.notes (#1874) next »