Home >Backend Development >PHP Tutorial >How to Get the First Day of the Current Month in PHP?

How to Get the First Day of the Current Month in PHP?

Linda Hamilton
Linda HamiltonOriginal
2024-11-05 09:53:02551browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn