Find weekday : strtotime « String « PHP






Find weekday

 
<?php

  function find_weekday($month, $year, $weekday, $offset=1)
  {
    $month_ts = strtotime("$year-$month-01");
    if(--$offset > 0)
      $month_ts = strtotime("+$offset week", $month_ts);
    $month_ts = strtotime($weekday, $month_ts);
    return $month_ts;
  }

  echo date('d M Y', find_weekday(5, 2000, "Friday")) . "<br />";
  echo date('d M Y', find_weekday(5, 2000, "Friday", 1)) . "<br />";
  echo date('d M Y', find_weekday(5, 2000, "Fri", 2)) . "<br />";
  echo date('d M Y', find_weekday(5, 2000, "Friday", 3)) . "<br />";
  echo date('d M Y', find_weekday(5, 2000, "Friday", 4));

?>
  
  








Related examples in the same category

1.Calculating a date interval with strtotime()
2.Checking a date range
3.int strtotime ( string time [, int now] ) converts strings to a timestamp
4.Using strtotime()
5.Using strtotime() with a starting epoch timestamp
6.Find the First monday on or after November 1, 2008
7.Finding the Date for a Weekday
8.Getting the Day and Week of the Year
9.If PHP is unable to convert your string into a timestamp, it will return -1.
10.Obtaining the Difference Between Two Dates
11.Subtracts a year from a given timestamp