2012-12-16 45 views
-4

可能重複:
How to calculate the difference between two dates using PHP?計算生日到年月日時分秒

有人能告訴我的代碼用於計算生日到年月日時分秒

例如:Aug 8, 1993

預期的結果會是這樣:

由於Dec 16, 2012 11:04 您的年齡是19 years 4 months 12 days 11 hours 4 minutes and 23 seconds

+0

在語言,你更喜歡哪個? – Kasun

+1

@Kasun它被標記爲PHP。 mkdate和日期是你的朋友 – rekire

+0

PHP請幫我:) – chachi

回答

1

試試這個

<?php 
     $birthday = new DateTime("2007-03-24"); 
     $today = new DateTime(); 
     $interval = $birthday->diff($today); 
     echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";  
    ?> 

How to calculate the difference between two dates using PHP?

+0

非常感謝你Kasun:* – chachi

+4

@Kasum:請不要複製答案,特別是因爲這個問題是重複的。相反,將問題本身下面的評論留下來作爲評論。 – hakre

+0

我也添加了鏈接,並修改了匹配@ cathe的要求 – Kasun

相關問題