How to realize the date several days after a given date (somewhat similar to DateAdd in VB)
/*
Tofu production are all excellent products
http://www.asp888.net Tofu Technology Station
If you reprint, please keep the complete copyright information
*/
In the past few days, many people suddenly asked this question, that is, how to implement the DateAdd function in VB in PHP, haha! This is a fair question.
Originally, this question was an exam question when Doufu applied for a job at Huawei, but it was implemented in C++ at the time. I didn't expect that such a big company would use such a pediatrician to take the exam:). Later I didn't go. In the past two days, I responded to the netizens of http://www.chinaspx.com - "Fortunately, I used PHP to restart
Write this function.
This function is very simple. It just adds one day to the specified time to get the newly generated date. If you want to expand it, it is also very simple.
Let’s first look at this function. First of all, we need to talk about a function in advance to determine whether it is a leap year.
function CheckRun($year){
if($year%4==0 && ($year %100!=0 || $year%400==0) )
return true;
else
return false;
}
We will use this function in the following program
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; //Stop talking nonsense, add the date first and then say it
if($month=='1' || $month=='3' || $ month=='5' || $month=='7' || $month=='8' || $month=='10' || $month=='12')
if($day ==32)
{
$day='1';