views:

389

answers:

5

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

+1  A: 

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.

Sarfraz
+1  A: 
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;
}
nik
+2  A: 

You can also do it at the database level using the DATEDIFF() function.

http://www.w3schools.com/SQl/func_datediff_mysql.asp

ILMV
+1  A: 
<?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";
ZZ Coder
A: 
DATEDIFF(CURDATE(),SUBSTR(ticket.created,1,10)) AS ticket_age

i fixed my ticket age using mysql query ,

Thanks

Bharanikumar