note 45430 deleted from function.date by derick

From: Date: Sun, 12 Jun 2005 11:43:49 +0000
Subject: note 45430 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-90293@lists.php.net to get a copy of this message
Note Submitter: pdontthink blah angry nerds blah com bla ---- Snippet for figuring out how to determine what week of the month a certain date (in the form of a timestamp or month/year/day) falls in: <?php /** * Determine the week of the month for a date * * The date in question may be given as a timestamp * or as separate day, month and year numbers * * @param int $timestamp The date in question * @param int $year The year of the date in question * @param int $month The month of the date in question * @param int $day The day of the date in question * * @return int The week of the month that the given * date falls within, or zero if error * */ function weekOfMonth($timestamp=0, $year=0, $month=0, $day=0) { // bunch of junk to figure out parameters // skip to last line to see what you really // wanted... // if ($month == 0 || $year == 0 || $day == 0) { if ($timestamp == 0) return 0; // error else list($month, $year) = explode(',', date('m,Y', $timestamp)); } else if ($month == 0 || $year == 0 || $day == 0) return 0; // error else $timestamp = mktime(0, 0, 0, $month, $day, $year); // not much to it; just subtract week of year // for the first of the month from the week of // the year for the target timestamp // return date('W', $timestamp) - date('W', mktime(0, 0, 0, $month, 1, $year)); } ?> Happy coding

« previous php.notes (#90293) next »