Efficient Age From Date of Birth Calculation - PHP edition
Well thought I would have a look at the same set of methods in PHP as I did in MS SQL. The order of efficiency did change somewhat, which was certainly interesting to me. Below is my simple code. $timeformatted = date("Y-m-d",strtotime('20th March 1954')); //Start test 1 $time_start = microtime(true); $datetime1 = new DateTime($timeformatted); $datetime2 = new DateTime("now"); $interval = date_diff($datetime1, $datetime2); echo " Test1 ".$interval->y ; $time_end = microtime(true); $time = ($time_end - $time_start)*100; echo " $time ms "; //start test2 $time_start2 = microtime(true); $japDate1 = str_replace("-","",$timeformatted); $japDate2 = date("Ymd",time()); $answer = floor(($japDate2 - $japDate1)/10000); echo " Test2 $answer "; $time_end2 = microtime(true); $time2 = ($time_end2 - $time_start2)*100; echo " $time2 ms "; //start test 3 $time_start