I have this...
$firstDate = $row['date']; // 2013-09-11 18:35:24
$secondDate = date("Y-m-d H:i:s");
$datetime1 = new DateTime($firstDate);
$datetime2 = new DateTime($secondDate);
$interval = $datetime1->diff($datetime2);
if($interval->y !== 0)
{
$elapsed = $interval->format('%y years ago');
}
else
if($interval->m !== 0)
{
$elapsed = $interval->format('%m months ago');
}
else
if($interval->a <= 7 && a >=1)
{
$elapsed = $interval->format('%a days ago');
}
else
if($interval->h !== 0)
{
$elapsed = $interval->format('%h hours ago');
}
else
if($interval->i !== 0)
{
$elapsed = $interval->format('%i minutes ago');
}
else
if($interval->S !== 0)
{
$elapsed = $interval->format('%S seconds ago');
}
$elapsed = str_replace(array('0 years ago', ' 0 months ago', ' 0 days ago', ' 0 hours ago', ' 0 minutes ago'), '', $elapsed);
$elapsed = str_replace(array('1 years ago', '1 months ago', '1 days ago', '1 hours ago', '1 minutes ago'), array('1 year ago', '1 month ago', '1 day ago', '1 hour ago', '1 minute ago'), $elapsed);
This code is supposed take the date in the database and convert into something people understand - 5 days ago, 5 seconds ago. But now a day later, the code seems to be skipping over the day.
I thought it had something to do with using %a instead fo %d but I got an error. What else could be wrong?
Thanks!