How to implement dates after a given date (somewhat similar to the DateAdd in VB)
/*
Tofu making is a boutique
Http://www.asp888.net Tofu Technology Station
If reproduced please retain the full copyright information
*/
These days suddenly a lot of people ask such a question, is how to implement in PHP in VB DateAdd function, hehe! But this is a question.
Originally this problem is tofu to Huawei applied for a test question, but it was implemented in C + +. Did not expect such a large company, unexpectedly
Then use this kind of pediatrics to test:), later I did not go, these two days should http://www.chinaspx.com of net friend-"luck, with PHP again
Wrote this function.
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 ';
http://www.bkjia.com/PHPjc/629283.html www.bkjia.com true http://www.bkjia.com/PHPjc/629283.html techarticle How to achieve the date of a given date after a number of days (somewhat similar to VB DateAdd)///Tofu production is a boutique http://www.asp888.net tofu technology station such as reproduced please retain the full copyright information ...