这是我的代码:
date_default_timezone_set('Asia/Kuala_Lumpur');
$date_join = $row['date_joined']; =produce 2012-09-03
$today = date("Y-m-d"); = produce 2014-08-29
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$a, **$xxx**);
如何在以下年份获得日期持续时间($ today - $ date_join):
服务日期:1。5年
答案 0 :(得分:1)
您可以使用PHP strtotime() function
。试试这个..
$join_date = '2012-09-03'; //join date
$today = date("Y-m-d"); //current date
$date_join = strtotime($join_date); // join date to seconds
$today = strtotime($today); //current date to seconds
$differenceInSeconds = $today - $date_join; // Time difference in seconds
echo number_format($differenceInSeconds / (365 * 24 * 60 * 60), 2) . ' Year(s)';