Getting first weekday in a month with strtotime

Building off the answers provided, one needs to be aware of differences in relative date formatting between php 5.2 and php 5.3.

TEST:

$date1 = strtotime("first wednesday of 2010-12");
$date2 = strtotime("first wednesday 2010-12");
$date3 = strtotime("wednesday 2010-12");

5.2 Results:

1969-12-31
2010-12-08
2010-12-01

5.3 Results:

2010-12-01
2010-12-08
2010-12-01

Therefore only the third method returns correct results across PHP 5 versions.

Leave a Comment