Posted By

aristoworks on 01/07/10


Tagged

php calendar date function mondays monday


Versions (?)

Retrieve All of the 'Monday's for a given year.


 / Published in: PHP
 

URL: http://www.aristoworks.com

This is a simple function that will return an array of all the dates corresponding to the day 'Monday' for a given year. It's pretty simple and may not be the cleanest way but it works for my purpose.

  1. function getMondays($year) {
  2. $newyear = $year;
  3. $week = 0;
  4. $day = 0;
  5. $mo = 1;
  6. $mondays = array();
  7. $i = 1;
  8. while ($week != 1) {
  9. $day++;
  10. $week = date("w", mktime(0, 0, 0, $mo,$day, $year));
  11. }
  12. array_push($mondays,date("r", mktime(0, 0, 0, $mo,$day, $year)));
  13. while ($newyear == $year) {
  14. $x = strtotime(date("r", mktime(0, 0, 0, $mo,$day, $year)) . "+" . $i . " week");
  15. $i++;
  16. if ($year == date("Y",$x)) {
  17. array_push($mondays,date("r", $x));
  18. }
  19. $newyear = date("Y",$x);
  20. }
  21. return $mondays;
  22. }

Report this snippet  

You need to login to post a comment.