Jump to content


This topic is now archived and is closed to further replies.


Time Function Question

Recommended Posts


I want to show this kinda message "You last logged in '3 days 2 hours and 5 seconds ago".

I have a date and time saved in database, is there a function to calculate the difference between the times?The field in the db is "datetime" but does it have to be "timestamp"?


Share this post

Link to post
Share on other sites
PHP does not have a datediff function like ASP, but it is relatively easy.

Take date 1 and use the date fucntion to return you seconds.

$loggedIn = date("U", mktime(h,m,s,m,d,y));

and right now is

$now = date("U");

take $now - $loggedIn and you now have the SECONDS that have passed between the two dates.

I day is 86400 seconds, 1 hour is 3600 seconds, one minute 60 seconds.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.