note 84906 deleted from ref.datetime by danbrown
| From: | danbrown@php.net | Date: | Wed, 20 May 2009 02:45:20 +0000 |
| Subject: | note 84906 deleted from ref.datetime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155771@lists.php.net to get a copy of this message | ||
Note Submitter: ryan
----
Actually in regards to sagar's week functionality, there's a much better way. Well, to at
least get the start_timestamp. I'm sure y'all can figure out the end_timestamp on your
own. This is part of a script I wrote some time back and uses $_GET['year'] and
$_GET['week'] if the user was moving around the calendar. Otherwise it loaded the current
week.
Some might ask about January 4th, but according to the official ISO specification or something,
January 4th is always in week 1, so it works out.
Oh... and it doesn't work with daylight savings time as well but since it starts on a Monday,
for the most part, it won't affect really anything.
<?php
// Get today
$date = time();
// Get times (minute, hour, day) in seconds
$ms = 1 * 60;
$hs = 1 * 60 * $ms;
$ds = 1 * 24 * $hs;
// Get first day in the week
if ( is_numeric($_GET['year']) && is_numeric($_GET['week']) )
{
$first = strtotime('January 4 '.$_GET['year'].' +
'.($_GET['week'] - 1).' weeks');
$first = $first - $ds * ( date('w', $first) - 1 );
}
else
$first = $date - ( $ds * ( date('w', $date) - 1 ) + $hs * date('H', $date) +
$ms * date('i', $date) + date('s', $date) );
?>