PHP obtains the date (strtotime (), date () of the previous month, next month, and this month ()). When I was writing a program today, I suddenly found a function that was written a long time ago to get the number of days of the month. The classic switch version, but when I got the number of days of the previous month, I only set the month to 1, it is estimated that when I write a program today, I suddenly find the function to get the number of days of the month written a long time ago. it is a classic switch version, but when I get the number of days of the previous month, I just took the month-1. I guess it was too difficult at the time. then I saw a strange feeling. I wanted to deal with it again, but there must be some very convenient method, so I found the following version and made some minor changes.
Get the date of this month:
getMonth( = ("Y-m-01",( = ("Y-m-d",(" +1 month -1 day" (, }
$ Firstday is the first day of the month. if $ date is like 2014-2, $ firstday will be. Then, add a month based on $ firstday to, and then subtract one day from, it is really convenient to use date () and strtotime.
Get Last Month Date:
getlastMonthDays( =( =('Y-m-01',(('Y',).'-'.(('m',)-1).'-01' =('Y-m-d',(" +1 month -1 day" (, }
You need to get a timestamp for the last month, and then-1 in the month will be OK. the super intelligent date () will convert 2014-0-1 to, which is so nice.
Obtain the date of next month:
getNextMonthDays( =( =( (['mon'] == 12 =['year'] +1 =['mon'] -11 =.'-0'..'-01' =('Y-m-d',(" +1 month -1 day" } =('Y-m-01',(('Y',).'-'.(('m',)+1).'-01' =('Y-m-d',(" +1 month -1 day" (, }
The code for the next month's date looks a little longer, because date () cannot be converted into something similar to 2014-13-01, and it will return directly to 1970, so we need to deal with the issue of December before, in addition to December, the month + 1 is OK.
In general, it is very convenient. the date function is too powerful.
...