How does PHP calculate the age and domain name age? YYYY-mm-dd is known. Domain age

Source: Internet
Author: User
How does PHP calculate the age and domain name age? YYYY-mm-dd is known. Ask for the domain name age. How to calculate domain names has been plagued for a long time. I wrote a function myself, but it is wrong, because some years are in a leap year. & Lt ;? Php & nbsp; // Time input must be in the unit function & nbsp PHP. how do I calculate the age and domain name age? YYYY-mm-dd is known. Ask for the domain name age.
How to calculate domain names has been plagued for a long time. I wrote a function myself, but it is wrong, because some years are in a leap year.




// The unit required for time input
Function mathAge ($ ymd2 ){
$ Ymd1 = "2012-2-27 ";
@ List ($ y1, $ m1, $ d1) = explode ("-", date ("Y-m-d", strtotime ($ ymd1 )));
@ List ($ y2, $ m2, $ d2) = explode ("-", date ("Y-m-d", strtotime ($ ymd2 )));

$ Arr = array (
"Year" => round ($ y1-$ y2 ),
"Month" => round ($ m1-$ m2 ),
"Day" => round ($ d1-$ d2 ),
);

$ Arr ["day"] = round ($ d1-$ d2 );
While ($ arr ["day"] <0 ){
$ Arr ["day"] + = 30;
$ Arr ["month"]-= 1;
}

While ($ arr ["month"] <0 ){
$ Arr ["month"] + = 12;
$ Arr ["year"]-= 1;
}
$ Txt = '';
Foreach ($ arr as $ k => $ v)
{
If (! $ V) continue;
$ Txt. = $ v. $ k;
}
Echo "$ ymd1-$ ymd2 = $ txt \ n ";
Return $ txt;
}

$ DateArr = array (
"2011-12-28 ",
"2011-12-29 ",
"2011-12-27 ",

"2010-12-28 ",
"2010-12-29 ",
"2010-12-27 ",

"2011-10-1 ",
"2010-5-1 ",
"2010-2-28 ",

"1995-1-1 ",
"1995-12-31 ",
);
Foreach ($ dateArr as $ date)
{
MathAge ($ date );

}
?>



The output test content is as follows:


January 29-= day
January 28-= day
February-
January 29-
January 28-
February-
April 26-2011-10-1 = October
September 26-
November 29-= 1-
January 26-= 17-
January 26-

How can we calculate the year and month of the difference between two dates? The leap year May.
------ Solution --------------------
Well, I am not very clear about it, but I 'd like to discuss it with you.

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.