note 8685 added to Date and Time functions
| From: | jon at gaarsmand dot dk | Date: | Sun, 24 Sep 2000 00:53:17 +0000 |
| Subject: | note 8685 added to Date and Time functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-5396@lists.php.net to get a copy of this message | ||
Need the week of the month?
Heres a function that should do the trick:
/*Call the function as:
weekofmonth(year,month,date)
- either can be int's or strings with leading 0's.
If theres no arguements today will be the arguements.
Output is in the form "YYYYmmw" where "w" represents the week of the month.
*/
function weekofmonth($yr=0,$mn=0,$dd=0) {
if(!($yr>0&$mn>0&$dd>0)) {
$yr=date("Y");$mn=date("m");$dd=date("d"); }
$thisweek = strftime("%U",mktime(0,0,0,$mn,$dd,$yr));
$firstweekofmonth =
strftime("%U",mktime(0,0,0,date("m",mktime(0,0,0,$mn,$dd+(6-date("w",mktime(0,0,0,$mn,$dd,$yr))),$yr)),1,$yr));
$thisweek = (abs($thisweek-$firstweekofmonth)>5) ? $firstweekofmonth:$thisweek;
return
date("Y",mktime(0,0,0,$mn,$dd+(6-date("w",mktime(0,0,0,$mn,$dd,$yr))),$yr)).date("m",mktime(0,0,0,$mn,$dd+(6-date("w",mktime(0,0,0,$mn,$dd,$yr))),$yr)).(($thisweek
- $firstweekofmonth) + 1);
}
http://www.php.net/manual/ref.datetime.php