Get the First/Last Day of a Week, Month, Quarter or Year in PHP

If you’ve ever needed to find the first or last day of a given period and you’re rocking a PHP version greater than or equal to 5.2, today is your lucky day!

Both of these functions return a DateTime object, so you can output the date in any format available to the PHP date() function.

Get the First Day of a Week, Month, Quarter or Year

Get the Last Day of a Week, Month, Quarter or Year

Here is a usage example of both functions:

This is the output of the above usage example when run today:

I hope you find these functions useful!