note 84433 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 26 Oct 2008 13:00:30 +0000 |
| Subject: | note 84433 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145773@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.
?>