Reputation: 2944
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.
Upvotes: 4
Views: 7047
Reputation: 306
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:
Upvotes: 6
Reputation: 73292
If your PHP is >= 5.3.0 you can use the DateTime::diff method.
Upvotes: 2