How to implement a date several days after a given date (somewhat similar to DateAdd in VB)_PHP Tutorial

WBOY
Release: 2016-07-13 17:12:52
Original
763 people have browsed it

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';

http://www.bkjia.com/PHPjc/629283.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629283.htmlTechArticleHow to achieve a date several days after a given date (somewhat similar to DateAdd in VB) /* Tofu making It is a high-quality product http://www.asp888.net If the Tofu Technology Station is reproduced, please retain the complete copyright information...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!