So, I have the following mysql time format:
date_default_timezone_set('Canada/Mountain');
$date = date('Y-m-d H:i:s', time());
'post_data' => $date,
Giving "2016-01-25 13:26:07"
format.
To change its format to "ago" I used the following:
//Time to ago
function ago($time)
{
$periods = array("second", "min", "hr", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$difference = $now - $time;
$tense = "ago";
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j]";
}
However, all the new row input gets "7hr" as its time when it should be "1 second" (as it is a new input).
Any suggestions to how to fix this?
Thanks