note 8685 deleted from ref.datetime by cece

From: Date: Wed, 20 Aug 2003 13:42:06 +0000
Subject: note 8685 deleted from ref.datetime by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54751@lists.php.net to get a copy of this message
Note Submitter: jon@gaarsmand.dk ---- 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); }

« previous php.notes (#54751) next »