Search code examples
phpdatestrtotimeunix-timestamp

PHP find first Thursday in a month


I'm working on a time management program and was wondering how I would find the first Thursday in a certain month. Does PHP have any functions to aid with this? strtotime doesn't want to format some strings properly.

If i use strtotime("first thursday december 2011") it returns 1323302400 which is actually the second thursday (8th december).

If i use strtotime("first thursday december 2011 - 1 week") it returns 1322092800 which is 24th November.

Can someone lend a hand please!


Solution

  • Read PHP Bug #53539. The fix is to use of: strtotime("first thursday of december 2011")

    Note that many DateTime bugs were fixed in PHP 5.3. If you are running < 5.3 you should really upgrade.