note 64843 added to function.mktime
| From: | adrianduyzer at gmail dot com | Date: | Fri, 21 Apr 2006 17:00:12 +0000 |
| Subject: | note 64843 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108940@lists.php.net to get a copy of this message | ||
Here's a quick function that will return the timestamp corresponding to the first weekday in a
given year. E.g. if you want to get the first Monday in a given year, or the first Sunday, this
function will do that for you.
<?php
// returns the timestamp of the given weekday number in the given year
// $weekday is 0 for Sunday, 1 for Monday, etc.
function getFirstDayStamp($year, $weekday)
{
// get the stamp for the first day of the year (January 1)
$jan1 = mktime(1,1,1,1,1,$year);
$jan1_weekday = date('w', $jan1);
$delta = $weekday - $jan1_weekday;
if ($delta >= 0) {
return(mktime(1,1,1,1,1 + $delta, $year));
} else {
// negative deltas pull us into previous year so add 7
return(mktime(1,1,1,1,(1 + $delta) + 7, $year));
}
}
?>
----
Server IP: 66.207.199.35
Probable Submitter: 24.150.120.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- http://master.php.net/note/edit/64843
Del: integrated -- http://master.php.net/note/delete/64843/integrated
Del: useless -- http://master.php.net/note/delete/64843/useless
Del: bad code -- http://master.php.net/note/delete/64843/bad+code
Del: spam -- http://master.php.net/note/delete/64843/spam
Del: non-english -- http://master.php.net/note/delete/64843/non-english
Del: in docs -- http://master.php.net/note/delete/64843/in+docs
Del: other reasons-- http://master.php.net/note/delete/64843
Reject -- http://master.php.net/note/reject/64843
Search -- http://master.php.net/manage/user-notes.php