How to find the age between two date using php or mysql
2009-09-24 21:09:36 2010-03-04 13:24:58
Thanks
How to find the age between two date using php or mysql
2009-09-24 21:09:36 2010-03-04 13:24:58
Thanks
You can use this excellent function by addedbytes to find it i think.
echo datediff('yyyy', '2009-09-24 21:09:36', '2010-03-04 13:24:58);
Check out the function parameters for more info.
function dateDiff($endDate, $beginDate)
{
$date_part1=explode(" ", $beginDate);
$date_part2=explode(" ", $endDate);
$date_parts1=explode("-", $date_part1[0]);
$date_parts2=explode("-", $date_part2[0]);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}
You can also do it at the database level using the DATEDIFF()
function.
<?php
$diff = strtotime('2010-03-04 13:24:58') - strtotime('2009-09-24 21:09:36');
echo "Difference is $diff seconds\n";
$days = floor($diff/(3600*24));
echo "Difference is $days days\n";
DATEDIFF(CURDATE(),SUBSTR(ticket.created,1,10)) AS ticket_age
i fixed my ticket age using mysql query ,
Thanks