Words not much to say, directly on the code:
$BeginDate = "2015-05-31";//New Gets the last 1 days of the specified month echo date ("Y-m-t", Strtotime ("+1 months", Strtotime ($BeginDate)));
Based on experience, the results should be: 2015-06-30
But the actual operation result is not, everybody please try, and ask everybody this is why ~ ~ ~ knocked Me Out
Another: If the start time is set to 2015-05-30 the calculation result is correct
Reply to discussion (solution)
$BeginDate = "2015-05-31"; Echo date ("Y-m-d T", Strtotime ("+1 months $BeginDate"));
2015-07-01 on 31
What's the problem?
May 31 plus One months (June is 30 days) so that's July 1, the last day of July is 31st?
Looks like something's wrong with your experience.
Oh, study.
I thought +1 months was the next month of that month.
If so I think PHP has a bug, this situation should not go into 1, but should return to the last day of June
You understand the error!!
Get another syntax for the last day of the next month.
Oh, plus one months, it must be July 1.
If according to your logic, plus one day that's not equal to May 31?
Bug You're not dealing with the logic.
I usually use the next month, 1st, minus another 1 days.
I changed the algorithm, is a good solution to this problem
Although there are many ways, I still insist that this is a PHP bug, as the first floor said, May has 31 days so +1 months is June 31, but June has 30 days, so the result is July 1, then this strtotime +1 months is bug!
The way to change yourself is:
$begindate = "2015-05-31"; $enddate =date ("y-m-01", Strtotime ($begindate));//Get $enddate=date at the beginning of the month ("Y-m-t 23:59:59", Strtotime ("$enddate +1 Month");//month plus 1 month then calculate the last day of the month
$BeginDate = "2015-05-31"; Echo date ("Y-m-d T", Strtotime ("+1 months $BeginDate"));
2015-07-01 on 31
What's the problem?
May 31 plus One months (June is 30 days) so that's July 1, the last day of July is 31st?
Looks like something's wrong with your experience.
How is PHP's plus one months calculated? May 31 plus one month is the simple May +1=6 month 31st? Then June 31 does not exist so the result is July 31?
If May 31 plus one day is 32 days, but 32 days does not exist is June 1?
I understand that, right?
Yes
But please note: This is not a PHP rule, but a rule of time in English.