Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $predefinedYear = 2009;
- $predefinedWeeks = 47;
- // find first mоnday of the year
- $firstMon = strtotime("mon jan {$predefinedYear}");
- // calculate how much weeks to add
- $weeksOffset = $predefinedWeeks - date('W', $firstMon);
- // calculate searched monday
- $searchedMon = strtotime("+{$weeksOffset} week " . date('Y-m-d', $firstMon));
- //To calculate 12 th Monday from this Monday(2014-04-07)
- $n_monday=12;
- $cur_mon=strtotime("next Monday");
- for($i=1;$i<=$n_monday;$i++){
- echo date('Y-m-d', $cur_mon);
- $cur_mon=strtotime(date('Y-m-d', strtotime("next Monday",$cur_mon)));
- }
- 2014-04-07
- 2014-04-14
- 2014-04-21
- 2014-04-28
- 2014-05-05
- 2014-05-12
- 2014-05-19
- 2014-05-26
- 2014-06-02
- 2014-06-09
- 2014-06-16
- 2014-06-23
- function getMondaysDate($year, $week) {
- if (!is_numeric($year) || !is_numeric($week)) {
- return null;
- // or throw Exception, etc.
- }
- $timestamp = strtotime("+$week weeks Monday January $year");
- $prettyDate = date('d M Y');
- return $prettyDate;
- }
- date('c',strtotime('Sunday Jan 2018'));
- // "2018-01-07T00:00:00+11:00" (or whatever your timezone is)
- date('c',strtotime('+1 weeks Sunday Jan 2018'));
- // "2018-01-14T00:00:00+11:00" (or whatever your timezone is)
- date('c',strtotime('+52 weeks Sunday Jan 2018'));
- // "2019-01-06T00:00:00+11:00"
Add Comment
Please, Sign In to add comment