This function is very simple, that is, add a day to the specified time, get the new generation of the date, if you want to expand, it is very simple.
First of all, this function, first of all, to tell a function in advance to determine whether the current is a leap year function
function CheckRun ($year) {
if ($year%4==0 && ($year%100!=0 | | $year%400==0))
return true;
Else
return false;
}
We're going to have this function in the following procedure.
function DateAdd ($date) {
$parts = Explode (' ', $date);
$date = $parts [0];
$time = $parts [1];
$ymd = Explode ('-', $date);
$hms = Explode (': ', $time);
$year = $ymd [0];
$month = $YMD [1];
$day = $ymd [2];
$hour = $hms [0];
$minute = $hms [1];
$second = $hms [2];
$day = $day +1; Cut the crap, add the date first.
if ($month = = ' 1 ' | | $month = = ' 3 ' | | $month = = ' 5 ' | | $month = = ' 7 ' | | $month = = ' 8 ' | | $month = = ' 12 ')
if ($day ==32)
{
$day = ' 1 ';
$month + +;
}
if ($month = = ' 4 ' | | $month = = ' 6 ' | | $month = = ' 9 ' | | $month = = ' 11 ')
if ($day ==31)
{
$day = ' 1 ';
$month + +;
}
if ($month = = ' 2 ')
if (CheckRun ($year))
{
Leap year February has 29 days
if ($day ==30)
{
$day = 1;
$month + +;
}
}
Else
{
Not a leap year
if ($day ==29)
{
$day = 1;
$month + +;
}
}
if ($month ==13)
{
$month = 1;
$year + +;
}
Return $year. "-" . $month. "-" . $day;
}
Okay, here's the test.
Echo DateAdd ("2013-12-31 11:11:11");
Echo DateAdd ("2014-2-29 11:11:11");
The above describes how PHP implements the date after a certain number of days of the specified date, including aspects of the content, I hope to be interested in the PHP tutorial friends helpful.