How to find the number of day's before the event happen compare to current date , i having Linux time in my database i am converting the Linux to ordinary time like 2012-05-28 17:25:43,
i am tried like this its not working
$sql_sms_transactions = "SELECT MAX(`sendtime`) FROM `sms_transaction` where customer_id='$customer_id'";
$result_sms_transactions = mysql_query($sql_sms_transactions);
while($row2=mysql_fetch_assoc($result_sms_transactions))
{
$status = $row2['MAX(`sendtime`)'];
$timestamp2 = $status;
$ptime= gmdate("Y-m-d H:i:s", $timestamp2);
function time_elapsed_string($ptime)
{
$etime = time() - $ptime;
if ($etime < 1)
{
return '0 seconds';
}
$a = array( 12 * 30 * 24 * 60 * 60 => 'year',
30 * 24 * 60 * 60 => 'month',
24 * 60 * 60 => 'day',
60 * 60 => 'hour',
60 => 'minute',
1 => 'second'
);
foreach ($a as $secs => $str)
{
$d = $etime / $secs;
if ($d >= 1)
{
$r = round($d);
return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago';
}
}
}
}
i want to compare this 2012-05-28 17:25:43
with current date (today) and find out how many days before it happens i want only days,
final out put text should be like xx Days Ago
Does anyone have a better solution or code thanks.....