1$dayofweek = date('w', strtotime($date));
2$result = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
1
2Things to be aware of when using week numbers with years.
3
4<?php
5echo date("YW", strtotime("2011-01-07")); // gives 201101
6echo date("YW", strtotime("2011-12-31")); // gives 201152
7echo date("YW", strtotime("2011-01-01")); // gives 201152 too
8?>
9
10BUT
11
12<?php
13echo date("oW", strtotime("2011-01-07")); // gives 201101
14echo date("oW", strtotime("2011-12-31")); // gives 201152
15echo date("oW", strtotime("2011-01-01")); // gives 201052 (Year is different than previous example)
16?>
17
18Reason:
19Y is year from the date
20o is ISO-8601 year number
21W is ISO-8601 week number of year
22
23Conclusion:
24if using 'W' for the week number use 'o' for the year.
25