I have a post where I need the Time posted within my success function. My original link looks like this for php.
echo "<br/><a href='#' class='subtleLink' style='font-weight:normal;'>".Agotime($streamitem_data['streamitem_timestamp'])."</a>";
And I'm building up my ajax and in my success function I need the Agotime also adding, but I don't know how to go about it, I've got the timestamp just need the function Agotime to do its stuff.
AJAX
<br/><a class='subtleLink' style='font-weight:normal;'>"+response['streamitem_timestamp']+"</a>
My Agotime is a function
function Agotime($date)
{
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if(empty($unix_date)) {
return "Bad date";
}
// is it future date or past date
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
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] {$tense}";
}
?>
I have figured it out. I added the Agotime into my insert page for when my Ajax makes its call. Works a charm.
$json = array();
$check = "SELECT streamitem_id, streamitem_timestamp FROM streamdata";
$check1 = mysql_query($check);
$resultArr = mysql_fetch_array($check1);
$json['streamitem_id'] = $resultArr['streamitem_id'];
$json['streamitem_timestamp'] = Agotime($resultArr['streamitem_timestamp']);