hanlonj Posted September 14, 2006 Share Posted September 14, 2006 Hi,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"?John Link to comment https://forums.phpfreaks.com/topic/20784-time-function-question/ Share on other sites More sharing options...
onlyican Posted September 14, 2006 Share Posted September 14, 2006 current time - that time Link to comment https://forums.phpfreaks.com/topic/20784-time-function-question/#findComment-92012 Share on other sites More sharing options...
bholbrook Posted September 14, 2006 Share Posted September 14, 2006 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. Link to comment https://forums.phpfreaks.com/topic/20784-time-function-question/#findComment-92024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.