Calculating number of years between 2 dates in PHP

前端 未结 5 1572
你的背包
你的背包 2020-12-30 19:32

I need to get the number of years from 2 dates provided. Here\'s my code:

function daysDifference($endDate, $beginDate)
{
   $date_parts1=explode(\"-\", $beg         


        
5条回答
  •  臣服心动
    2020-12-30 19:42

    On a PHP 5.2 box (yeah really, they still exist) so without DateTime::diff() support I ended up using this:

    $dateString='10-05-1975';
    $years = round((time()-strtotime($dateString))/(3600*24*365.25))
    

提交回复
热议问题