I went here. did I find the php bug? Calculate the last day of the next month! If you don't talk much about it, go directly to the code:
$ BeginDate = "2015-05-31"; // Obtain the echo date ("Y-m-t", strtotime ("+ 1 months ", strtotime ($ BeginDate )));
Based on experience, the calculation result should be:
But the actual running result is not. please try it and ask for help ~~~~ Confused me.
If you set the start time to, 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
Is there any problem?
January 1, plus one month (January 1, is 30 days). So it is July 22,. is the last day of June 31?
It seems that something went wrong with your experience.
Oh, I learned
I thought + 1 months is the next month of the month.
In this case, I think there is a bug in php. in this case, we should not enter one place, but return the last day of June.
An error occurred !!
Obtain the syntax for the last day of the next month.
A month later, it must be July 1.
If you add a day based on your logic, isn't it equal to May 31?
Bug? You didn't handle the logic well.
At the end of the month, I usually use 1st day of next month to subtract one day.
I changed the algorithm, which is a good solution to this problem.
Although there are many methods, I still insist that this is a PHP bug. as stated in the same building, if there are 31 days in July, then + 1 months will be in July, but there will be 30 days in July, so the result is July 1, so the strtotime + 1 months is a bug!
You can change it by yourself:
$ Begindate = "2015-05-31"; $ enddate = date ("Y-m-01", strtotime ($ begindate )); // Get $ enddate = date ("Y-m-t 23:59:59", strtotime ("$ enddate + 1 month") at the beginning of the month ")); // add 1 month at the beginning of the month and calculate the last day of the month
$BeginDate="2015-05-31";echo date("Y-m-d t",strtotime("+1 months $BeginDate"));
2015-07-01 31
Is there any problem?
January 1, plus one month (January 1, is 30 days). So it is July 22,. is the last day of June 31?
It seems that something went wrong with your experience.
How does one month of PHP addition work? If you add a month in March May 31, the simple year May + 1 = may June 31? So the calculation result is. why?
If you add one day on January 1, on November 2, but January 2 does not exist on November 2?
I understand this, right?
Yes
However, please note that this is not a php rule, but a time calculation rule in English.