Jump to content

Time Function Question


hanlonj

Recommended Posts

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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.