note 84906 added to ref.datetime
| From: | ryan at osu1 dot php dot net | Date: | Tue, 05 Aug 2008 14:59:32 +0000 |
| Subject: | note 84906 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143164@lists.php.net to get a copy of this message | ||
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) );
?>
----
Server IP: 208.69.120.35
Probable Submitter: 160.81.221.42
----
Manual Page -- http://www.php.net/manual/en/ref.datetime.php
Edit -- https://master.php.net/note/edit/84906
Del: integrated -- https://master.php.net/note/delete/84906/integrated
Del: useless -- https://master.php.net/note/delete/84906/useless
Del: bad code -- https://master.php.net/note/delete/84906/bad+code
Del: spam -- https://master.php.net/note/delete/84906/spam
Del: non-english -- https://master.php.net/note/delete/84906/non-english
Del: in docs -- https://master.php.net/note/delete/84906/in+docs
Del: other reasons-- https://master.php.net/note/delete/84906
Reject -- https://master.php.net/note/reject/84906
Search -- https://master.php.net/manage/user-notes.php