This topic is locked

how to convert date and time to X timeago format on ListPage

11/25/2015 3:15:13 AM
PHPRunner General questions
J
jackwood author

Have you try the function / jquery how to convert date and time to timeago format on ListPage in PHPR 8.1?
so, on Listpage can see format datetime in, 1 minute ago, or bla..bla.. ago.

romaldus 11/25/2015



Have you try the function / jquery how to convert date and time to timeago format on ListPage in PHPR 8.1?
so, on Listpage can see format datetime in, 1 minute ago, or bla..bla.. ago.



https://codeforgeek.com/2014/10/time-ago-implementation-php/

romaldus 11/25/2015

Example.

In PHPRUNNER, add the following function to AFTER APPLICATION INITIALIZED event (Source: http://www.phpdevtip...-ago-function/)") :



function time_ago( $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}";
}


In Visual editor, right click >properties on your Date Field. In View as tab, choose custom and add the following code:

$value = time_ago($value);
Sergey Kornilov admin 11/25/2015

You can also check TimeAgo plugin that does the same thing:

https://xlinesoft.com/marketplace/products_view.php?editid1=23