Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use php to obtain the number of days in the current month and the first and last day of the month, the first and last day of the month

Shulou Source: shulou.com Published: 2022-06-02 08:58:53 09月29日 Update

This article mainly introduces "how to use php to obtain the number of days of the month and the first and last day of the month, and the first and last day of the month". In the daily operation, I believe many people have doubts about how to use php to obtain the number of days of the month and the first and last day of the month, the first and last day of the month. The editor consulted all kinds of materials and sorted out a simple and useful method of operation. I hope it will be helpful for you to answer the question of "how to use php to get the number of days of the month and the first and last day of the month, and the first and last day of the month"! Next, please follow the editor to study!

1. Get the first and last day of the last month.

Echo date ('YmurmMuo01, strtotime ('-1 month'))

Echo ""

Echo date ('YmurmMuttong, strtotime ('-1 month'))

Echo ""

There are some problems with the above method. Modify it according to the bg5hfc reply.

The first day of last month:

Echo date ('Ymurm Murphy 01'), strtotime (date). ('- 1 month')); / / calculate that the first day of the month will be subtracted by another month.

The last day of last month:

Echo date ('Ymurm Murphy 01'), strtotime (date). ('- 1 day')); / / calculate the first day of the month minus one more day.

two。 Get the first and last day of the month.

$BeginDate=date ('Ymurmmur01mm, strtotime (date ("Y-m-d")

Echo $BeginDate

Echo ""

Echo date ("$BeginDate + 1 month-1 day")

Echo ""

3. Get the year, month, day and number of days of the day.

"echo" this month: ". Date (" t ")." days "

Echo "current year" .date ('Y')

Echo "current month" .date ('m')

Echo "what's the current date" .date ('d')

Echo ""

4. It is more practical to use functions and arrays to get the first and last day of the month.

Function getthemonth ($date)

{

$firstday = date ('Ymurmmur01mm, strtotime ($date))

$lastday = date ("$firstday + 1 month-1 day")

Return array ($firstday,$lastday)

}

$today = date ("Y-m-d")

$day=getthemonth ($today)

Echo "first day of the month:". $day [0]. "the last day of the month:". $day [1]

Echo ""

At this point, the study on "how to use php to obtain the number of days of the month and the first and last day of the month, the first and last day of the month" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Days study practical year method more month problem help next function array article theory knowledge article website material follow face to face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Redmi Linux macOS