Home >Backend Development >PHP Tutorial >How to Get the First Day of the Current Month in PHP?
Retrieving the First Day of the Current Month in PHP Using Date_modify
Determining the day of the week can be effortlessly achieved using date_modify. However, finding the first day of the current month may require a slightly different approach.
Solution:
To obtain the first day of the current month, you can utilize the date() function. By specifying 'Y-m-01' as the argument within the date() function, you can retrieve the first day of the current month in the format 'YYYY-MM-DD'.
Example Code:
<code class="php">echo date('Y-m-01');</code>
Output:
2023-03-01
This code will display the first day of the current month, which in this case is '2023-03-01'.
The above is the detailed content of How to Get the First Day of the Current Month in PHP?. For more information, please follow other related articles on the PHP Chinese website!