Find difference between two dates is very easy to find out using simple SQL queries, suppose we want to check,the duration a user logged in.
There is another scenario where one may wish to see the number of days since user last logged in.
SELECT TIME_TO_SEC( TIMEDIFF( COL_LOGOUT_TIME , COL_LOGIN_TIME ) ) AS INTERVAL_IN_SECONDS FROM UsersAbove query will return number of seconds between last logout and login time you can format it using PHP strtotime() and date() functions , COL_LOGOUT_TIME,COL_LOGIN_TIME are column names.
There is another scenario where one may wish to see the number of days since user last logged in.
SELECT DATEDIFF(CURDATE(), COL_LOGOUT_TIME) AS INTERVAL_IN_DAYS FROM Usersabove query will return number of days between current date and COL_LOGOUT_TIME.
0 comments:
Post a Comment