How does PHP calculate age, domain name age? Known yyyy-mm-dd. Seek the age of the domain

Source: Internet
Author: User
How does PHP calculate age, domain name age? Known yyyy-mm-dd. To find the age of the domain.
How to calculate the age of a domain name it's been a long time since I wrote a function, but it's wrong, because some years are a leap year.




Time input must unit
function Mathage ($ymd 2) {
$ymd 1 = "2012-2-27";
@list ($y 1, $m 1, $d 1) = Explode ("-", Date ("Y-m-d", Strtotime ($ymd 1)));
@list ($y 2, $m 2, $d 2) = Explode ("-", Date ("Y-m-d", Strtotime ($ymd 2)));

$arr = Array (
"Year" = Round ($y 1-$y 2),
"Month" = Round ($m 1-$m 2),
"Day" = Round ($d 1-$d 2),
);

$arr ["Day"] = Round ($d 1-$d 2);
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 "$ymd 1-$ymd 2 = $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 above output test content is:













How to calculate the difference between the two dates? Consider leap year February.
------Solution--------------------
Well, I am not very clear, but deliberately come to the top of the landlord
  • 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.