Posted X ago |
[eluser]stuffradio[/eluser]
Is there a helper that can give me this result? Say if I posted a comment, I want to be able to see Comment 12345 "posted 20 seconds ago." Thanks!
[eluser]richthegeek[/eluser]
you store a timestamp with the comment by using time(). To get the number of seconds ago, take the timestamp away from the current time(). You can use various divisions (60, 3600, 86400) to get the number of minutes, hours, and/or days ago.
[eluser]stuffradio[/eluser]
Can you tell me what it is? This Code: $minutes = $images->time - time() / 3600; Code: Posted: Minutes 1214965913.3422 ago.
[eluser]richthegeek[/eluser]
You need to wrap your sums... Code: $minutes = round( ( $images->time - time() ) / 3600 ); This would be best used in the form of a model, so that your images model would retrieve the data from the database and work out the number of minutes, hours, seconds, days, etc ago - either automagically or via a direct function call.
[eluser]richthegeek[/eluser]
hey man, my bad XD take the Image->time from teh current time, not the current way. Code: $minutes = round( ( time() - $images->time ) / 3600 );
[eluser]Michael Wales[/eluser]
The Date Helper has the timespan() function built-in. It can get very specific though - a bit to specific for my tastes, so I use the following. Just throw it in your own helper file and load it. Code: // Probably not an accurate name, since we go down to minutes if need be I take the wierd route of returning the minutes just because I think it looks better. Do the users really care if it was 18 minutes ago? When you read 18 minutes you immediately think, 15 minutes ago. Makes it a bit more user-friendly to round them out to the quarter hour.
[eluser]avinashv[/eluser]
[quote author="Michael Wales" date="1215371484"]I take the wierd route of returning the minutes just because I think it looks better. Do the users really care if it was 18 minutes ago? When you read 18 minutes you immediately think, 15 minutes ago. Makes it a bit more user-friendly to round them out to the quarter hour.[/quote] In that case, I would probably make it explicit that you're being fuzzy with the time ala "about 15 minutes ago" rather than straight up write 15 minutes. Handy function though, I'm going to hang on to it, thanks. |
Welcome Guest, Not a member yet? Register Sign In |