Re: SELECT date query
| From: | Hodicska Gergely | Date: | Sat, 07 Oct 2006 08:28:18 +0000 |
| Subject: | Re: SELECT date query | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42502@lists.php.net to get a copy of this message | ||
Hi!
You can make this easier with date('w').
$correction = array(3, 2, 1, 7, 6, 5, 4);
list($year, $month, $day, $dayOfWeek) = explode('|', date('Y|m|d|w'));
echo date ("Y.m.d", mktime (0,0,0,$month,$day+$correction[$dayOfWeek],$year));
Regards,
Felhő
Niel Archer wrote:
Hi Ron
I've made the assumption that if today is Wednesday, you still want next
Wednesday.
Try this:
$offset = array(3,2,1,7,6,5,4);
$date = explode("-", date("Y-n-j"));
$ToDay = DayOfWeek($date[0], $date[1], $date[2]);
$NextWed = date("Y-n-j", time() + ($offset[$ToDay] * 24 * 60 * 60));
// Returns a digit in range 0-6. 0 = Sunday, 6 = Saturday
function DayOfWeek($Year, $Month, $Day)
{
$t = array(0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4);
$Year -= $Month < 3;
return ($Year + ($Year / 4) - ($Year / 100) + ($Year / 400) +
$t[$Month - 1] + $Day) % 7;
}
Niel