0

I currently have a database which contains last_login and last_logout columns with the datatype set to datetime. When a user logs in and logs out of the system, the time is updated in both of those columns.

I would now like to create a notification that informs the user of when they previously logged into the system. I would like to display the answer in hours, for example (23 hours ago or 128 hours ago).

I just can't figure out how to perform calculations in PHP with the values in each of these columns. Please help.

I apologise if this question is hard to understand.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183

2 Answers2

0
SELECT (TIME_TO_SEC(TIMEDIFF(LOGOUT_COLUMN, LOGIN_COLUMN)) / 3600) AS TimeDiff

should do the trick, will return in seconds the difference and then on PHP side you can convert that in minutes or hours.

GGio
  • 7,563
  • 11
  • 44
  • 81
0

Do it in mysql

Select TimeStampDiff(HOUR,LastLoginTime,Now()) From MyLoginTable

For instance

Tony Hopkinson
  • 20,172
  • 3
  • 31
  • 39