A small function to get the first weekday of the month.
For example the first monday of the month, or the first
friday, etc.
<?php
/**
*
* Gets the first weekday of that month and year
*
* param int The day of the week (0 = sunday, 1 =
monday ... , 6 = saturday)
* param int The month (if false use the current
month)
* param int The year (if false use the current
year)
*
* return int The timestamp of the first day of that
month
*
**/
function get_first_day($day_number=1, $month=false,
$year=false)
{
$month = ($month === false) ? strftime("%m"):
$month;
$year = ($year === false) ? strftime("%Y"):
$year;
$first_day = 1 + ((7+$day_number -
strftime("%w", mktime(0,0,0,$month, 1,
$year)))%7);
return mktime(0,0,0,$month, $first_day, $year);
}
// this will output the first wednesday of january 2007 (wed
03-01-2007)
echo strftime("%a %d-%m-%Y", get_first_day(3, 1,
2007));
?>
----
Server IP: 83.137.20.107
Probable Submitter: 82.204.37.70
----
Manual Page -- ht
tp://www.php.net/manual/en/function.strftime.php
Edit -- https://master
.php.net/note/edit/77489
Del: integrated -- h
ttps://master.php.net/note/delete/77489/integrated
Del: useless -- http
s://master.php.net/note/delete/77489/useless
Del: bad code -- htt
ps://master.php.net/note/delete/77489/bad+code
Del: spam -- https:/
/master.php.net/note/delete/77489/spam
Del: non-english --
https://master.php.net/note/delete/77489/non-english
Del: in docs -- http
s://master.php.net/note/delete/77489/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/77489
Reject -- https://mast
er.php.net/note/reject/77489
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|