4

Is it possible to make a date based on the weekday in a given month and year.

Givens are Month and Year. For instance, let's assume we are in March 2013.

We need too know the third Tuesday. So our ending result would be March 19, 2013

Other examples Weekdays Given in the March 2013:

First Friday March 1, 2013

First Monday March 4, 2013

Third Wednesday March 20, 2013

Fifth Sunday March 31, 2013

Fourth Saturday March 23, 2013

user2226714
  • 63
  • 1
  • 7
  • I think, it's been pretty much answered here: http://stackoverflow.com/questions/924246/get-the-first-or-last-friday-in-a-month – Michael Mar 31 '13 at 22:03

2 Answers2

1

you are looking for http://php.net/manual/en/function.strtotime.php

this accepts strings such as "first monday in march" "last wednesday in august" as date strings and gives you the unix timestamp for these particular dates

bizzehdee
  • 20,289
  • 11
  • 46
  • 76
1

Using the DateTime class you can easily get the full date:

$dt = new DateTime('third tuesday march 2013');
echo $dt->format('l j. F Y');
// Tuesday 19. March 2013

There are quite a lot of valid strings that can be passed to the DateTime constructor.

Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52