Jump to content


Photo

Time Function Question


  • Please log in to reply
2 replies to this topic

#1 hanlonj

hanlonj
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 14 September 2006 - 08:54 PM

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

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 14 September 2006 - 09:29 PM

current time - that time
Tell me the problem, I will try tell you the solution

#3 bholbrook

bholbrook
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 14 September 2006 - 09:49 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users