This topic is locked
[SOLVED]

 Time Ago Plugin

1/27/2016 5:04:27 AM
PHPRunner General questions
Tandy author

I bought the Time Ago plugin from the market. I thought it would do what I wanted and it might. Just need to know how to set it up to do what I would like it to do.

I made up my own topic here because there is no forum for it. Hope that is OK.
What I would like to see if I can make it do is:

When someone makes up a new record. I would like it to stay as how old that record is. So the plugin would keep adding time to it.

Right now as it stands it keeps resetting to how long you viewed it. Least that is what it seems. If I stay on the page it grow in time. But if I refresh the page or come back to the page the Time Ago plugin starts over.

I would like to make it stay on how old the record is from the beginning.
Thanks for any help I could get on this.

James Tandy

Sergey Kornilov admin 1/27/2016

James,
TimeAgo is a plugin written by a third party but I'll try to answer this. As far as I understand this plugin is built on the top of JQuery timeago plugin (http://timeago.yarp.com/) which is specifically designed to track time and update page in real time.
If this is not what you need you can create a custom 'View as' type to calculate time difference in PHP code. You can find some useful code snippets here:

https://css-tricks.com/snippets/php/time-ago-function/

P
pmorenoc07 1/27/2016



I bought the Time Ago plugin from the market. I thought it would do what I wanted and it might. Just need to know how to set it up to do what I would like it to do.

I made up my own topic here because there is no forum for it. Hope that is OK.
What I would like to see if I can make it do is:

When someone makes up a new record. I would like it to stay as how old that record is. So the plugin would keep adding time to it.

Right now as it stands it keeps resetting to how long you viewed it. Least that is what it seems. If I stay on the page it grow in time. But if I refresh the page or come back to the page the Time Ago plugin starts over.

I would like to make it stay on how old the record is from the beginning.
Thanks for any help I could get on this.

James Tandy


Hi,

I did something like that using a PHP Time-ago function in this link

http://www.phpdevtips.com/2011/06/the-php-time-ago-function/

  1. After application initialized, so you can call it from anywhere.


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}";
}


2.Lets say that your DB field name is created_at. In the list page View as Custom.



$value = time_ago($value);


Hope this help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78657&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

Tandy author 1/29/2016



Hi,

I did something like that using a PHP Time-ago function in this link

http://www.phpdevtip...e-ago-function/

  1. After application initialized, so you can call it from anywhere.


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}";
}


2.Lets say that your DB field name is created_at. In the list page View as Custom.



$value = time_ago($value);


Hope this help <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=78667&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


Thank You that did help but I am still having problems.

My Database field is called submit_time and I have that as datetime. I put as you wrote as well as tried to put the view as date and default as now(). I have also tried making the view as time and default is now(). The date somewhat works but the time is not going into the database. When I view the database record in phpMyAdmin the submit_date only shows date and does not put the the time in: 2016-01-26 00:00:00.

What do I need to do to have the time added into the record?
Thank you for your help..

James

P
pmorenoc07 1/29/2016

Hi James
You need to change your database field submit_time to timestamp, Not Null and Default CURRENT_TIMESTAMP.
Also you put in the Add page Before record added

$values['submit_time']= NOW();


That's all



Thank You that did help but I am still having problems.

My Database field is called submit_time and I have that as datetime. I put as you wrote as well as tried to put the view as date and default as now(). I have also tried making the view as time and default is now(). The date somewhat works but the time is not going into the database. When I view the database record in phpMyAdmin the submit_date only shows date and does not put the the time in: 2016-01-26 00:00:00.

What do I need to do to have the time added into the record?
Thank you for your help..

James

Tandy author 1/29/2016



Hi James
You need to change your database field submit_time to timestamp, Not Null and Default CURRENT_TIMESTAMP.
Also you put in the Add page Before record added

$values['submit_time']= NOW();


That's all


Thanks a Lot.. Now that is working great.. Thank you for all your help..

James