note 64843 deleted from function.mktime by bjori
| From: | bjori@php.net | Date: | Thu, 01 Jun 2006 18:36:12 +0000 |
| Subject: | note 64843 deleted from function.mktime by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-112801@lists.php.net to get a copy of this message | ||
Note Submitter: adrianduyzer at gmail dot com
----
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));
}
}
?>