PHP Search Date on Weekdays

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

Givens - month and year. For example, suppose we are in March 2013.

We also need to know the third Tuesday. Thus, our final result will be March 19, 2013.

Other examples on weekdays in 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.

+4
source share
2 answers

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 few valid strings that can be passed to the DateTime constructor.

+1
source

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

this takes strings like “first monday march”, “last wednesday in august” as date strings and gives you a unix timestamp for these specific dates

+1
source

All Articles