note 45430 added to function.date

From: Date: Tue, 07 Sep 2004 03:42:23 +0000
Subject: note 45430 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-76121@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45430 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45430&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45430&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76121) next »