note 84434 deleted from function.strtotime by derick

From: Date: Sun, 03 Aug 2008 11:51:46 +0000
Subject: note 84434 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143105@lists.php.net to get a copy of this message
Note Submitter: shem_lexluger at yahoo.com ---- Assuming a week starts on Monday. To calculate the week number of the current date starting from a specified date, use this function: <?php function weekcounter($start_date) { $start_date = strtotime($start_date); $today = strtotime(date('d-m-Y')); $week = 1; while($start_date < $today) { $start_date = strtotime('next Monday', $start_date); $week++; } return $week; } ?> Example: //now = 14-07-2008 echo weekcounter('01-07-2008'); //prints 3 echo weekcounter('01-06-2008'); //prints 8 instead of 7; because 1st jun is a Sunday so it is week 1 and 2nd june is week 2. Feel free to tweak.

« previous php.notes (#143105) next »