Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing time elapsed with php

Tags:

php

time

I am wanting to show the time elapsed since the time posted for a blog or similiar, I am using php and I am storing the time posted as a unix timestamp but I cannot for the live of me work out how to show the time since it was posted using the stored timestamp.

like image 456
sea_1987 Avatar asked Feb 25 '23 20:02

sea_1987


1 Answers

If for example your posted timestamp is:

1289735677

You can also get the current timestamp by using time(), for example.

Then you can take your posted timestamp from the current one:

time() - 1289735677

In that way you will get the seconds elapsed. Now you can change them to human readable format for example.

See examples on how you can convert seconds to human readable format:

  1. http://www.phpro.org/examples/Convert-Seconds-To-Hours-Minutes-Seconds-Words.html

  2. http://www.laughing-buddha.net/php/lib/sec2hms/

like image 152
XViD Avatar answered Mar 29 '23 23:03

XViD