daily pastebin goal
86%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $predefinedYear = 2009;
  2. $predefinedWeeks = 47;
  3.  
  4. // find first mоnday of the year
  5. $firstMon = strtotime("mon jan {$predefinedYear}");
  6.  
  7. // calculate how much weeks to add
  8. $weeksOffset = $predefinedWeeks - date('W', $firstMon);
  9.  
  10. // calculate searched monday
  11. $searchedMon = strtotime("+{$weeksOffset} week " . date('Y-m-d', $firstMon));
  12.    
  13. //To calculate 12 th Monday from this Monday(2014-04-07)
  14.     $n_monday=12;
  15.     $cur_mon=strtotime("next Monday");
  16.     for($i=1;$i<=$n_monday;$i++){
  17.        echo date('Y-m-d', $cur_mon);
  18.        $cur_mon=strtotime(date('Y-m-d', strtotime("next Monday",$cur_mon)));
  19.     }
  20.    
  21. 2014-04-07
  22. 2014-04-14
  23. 2014-04-21
  24. 2014-04-28
  25. 2014-05-05
  26. 2014-05-12
  27. 2014-05-19
  28. 2014-05-26
  29. 2014-06-02
  30. 2014-06-09
  31. 2014-06-16
  32. 2014-06-23
  33.    
  34. function getMondaysDate($year, $week) {
  35.   if (!is_numeric($year) || !is_numeric($week)) {
  36.     return null;
  37.     // or throw Exception, etc.
  38.   }
  39.  
  40.   $timestamp = strtotime("+$week weeks Monday January $year");
  41.   $prettyDate = date('d M Y');
  42.   return $prettyDate;
  43. }
  44.    
  45. date('c',strtotime('Sunday Jan 2018'));
  46. // "2018-01-07T00:00:00+11:00" (or whatever your timezone is)
  47.  
  48. date('c',strtotime('+1 weeks Sunday Jan 2018'));
  49. // "2018-01-14T00:00:00+11:00" (or whatever your timezone is)
  50.  
  51. date('c',strtotime('+52 weeks Sunday Jan 2018'));
  52. // "2019-01-06T00:00:00+11:00"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top