note 106065 deleted from function.date by tularis
| From: | tularis@php.net | Date: | Sun, 12 Feb 2012 11:21:57 +0000 |
| Subject: | note 106065 deleted from function.date by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-186075@lists.php.net to get a copy of this message | ||
Note Submitter: zimplicit
----
This is how you can get the week starting date and ending date by giving a week number and the year.
<?php
function week_start_date($wk_num, $yr, $first = 1, $format = 'Y-m-d')
{
$wk_ts = strtotime('+' . $wk_num . ' weeks', strtotime($yr .
'0101'));
$mon_ts = strtotime('-' . date('w', $wk_ts) + $first . ' days',
$wk_ts);
return date($format, $mon_ts);
}
//Get starting date of week 40 2011
$sStartDate = week_start_date(40, 2011);
//Get the ending date of the same week
$sEndDate = date('Y-m-d', strtotime('+6 days', strtotime($sStartDate)));
//Get current week and year
$week = date('w');
$year = date('Y');
?>