These days, many people suddenly asked this question: how to implement the DateAdd function in VB in php! This is a question. This was originally an exam question when tofu went to Huawei to apply for a job, but it was implemented in C ++. I didn't think of such a big company, but I used such a pediatrics to take the test :). I didn't go, and I was lucky to go to www.chinaspx.com these two days, A lot of people have asked this question over the past few days about how to implement the DateAdd function in VB in PHP! This is a question.
This was originally an exam question when tofu went to Huawei to apply for a job, but it was implemented in C ++. Without thinking of such a big company
However, using this pediatrics to take the exam :), then I did not go, the two days should be http://www.chinaspx.com of netizens-"luck, with PHP again
Write this function.
This function is very simple, that is, adding a day to the specified time to get the new date. if you want to extend it, it is very easy.
Next, let's take a look at this function. First, let's talk about a function in advance to determine whether it is a leap year function.
Function CheckRun ($ year ){
If ($ year % 4 = 0 & ($ year % 100! = 0 | $ year % 400 = 0 ))
Return true;
Else
Return false;
}
We need to 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; // you can add the date first.
If ($ month = '1' | $ month = '3' | $ month = '5' | $ month = '7' | $ month = '8' | $ month = '10' | $ 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 ))
{
// 29 days for January 1, February
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. let's test it.
Echo DateAdd ("11:11:11 ");
Echo DateAdd ("11:11:11 ");
If you want to test the function for several days, you only need to add a loop. I believe everyone is a senior. This function is very simple :)