How to implement dates after a given date (somewhat similar to the DateAdd in VB) _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.