Given a week number, e.g. date -u +%W
, how do you calculate the days in that week starting from Monday?
Example rfc-3339 output for week 40:
2008-10-06
2008-10-07
2008-10-08
2008-10-09
2008-10-10
2008-10-11
2008-10-12
Given a week number, e.g. date -u +%W
, how do you calculate the days in that week starting from Monday?
Example rfc-3339 output for week 40:
2008-10-06
2008-10-07
2008-10-08
2008-10-09
2008-10-10
2008-10-11
2008-10-12
This will fail if
$week_number
is less than 10.I found a problem with this solution. I had to zero-pad the week number or else it was breaking.
My solution looks like this now:
If you've got Zend Framework you can use the Zend_Date class to do this:
PHP
Below post was because I was an idiot who didn't read the question properly, but will get the dates in a week starting from Monday, given the date, not the week number..
In PHP, adapted from this post on the PHP date manual page:
Output from
week_from_monday('07-10-2008')
gives:Another solution:
Example:
Out: