问题
this is my code:
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**);
how can i get date durations ($today - $date_join) in years like :
Date of services : 1.5 years
回答1:
You can use PHP strtotime() function
. Try like this..
$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)';
- Get time difference in seconds from two dates
- Divide the difference by one year equivalent seconds
来源:https://stackoverflow.com/questions/25560987/php-date-get-date-different-in-years