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.