note 22978 deleted from function.getdate by tomsommer

From: Date: Wed, 15 Sep 2004 16:38:34 +0000
Subject: note 22978 deleted from function.getdate by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76757@lists.php.net to get a copy of this message
Note Submitter: mike_r_goetz at hotmail dot com ---- Two related date issues regarding the 'week of year' and 'week of month'. Firstly, use this function to get the week of the year if your week starts on a Sunday: function week_of_year($day, $month, $year) { $timestamp = mktime(0,0,0,$month,$day,$year); $date = getdate($timestamp); $woy = date('W', $timestamp); if ($date['wday'] == 0) { $woy++; } return $woy; } Secondly, use the following function (based on the one above) to get the week of the month (eg. Jul 7, 2002 is in the 2nd week of July): function week_of_month($day, $month, $year) { return (week_of_year($day, $month, $year) - week_of_year(1,$month,$year) + 1); }

« previous php.notes (#76757) next »