I have table like this; I captured every thing:
id, username, email, last_login
I want to know if user has logged in today or not. Please help me in single query
I have table like this; I captured every thing:
id, username, email, last_login
I want to know if user has logged in today or not. Please help me in single query
First fire update query to update 'last_login' at every user login time, then try this query:
$query = "SELECT id, username, email, last_login FROM tbl_name WHERE last_login = NOW()";
if this query returns 1 that means user have logged in today into the system, otherwise not.
You need to update 'last_login' at every user login and to check if a user logged in use this query:
SELECT id, username, email, last_login FROM tbl_name WHERE CONVERT(date,last_login) = CONVERT(date,GETDATE())
If you want just checking and return a bool you can use this query:
SELECT CASE WHEN CONVERT(date,last_login) = CONVERT(date,GETDATE()) THEN 1 ELSE 0 END
Try with this before going with this ensure that the login user has to update his last login
select id, username, email, last_login from table_name where last_login=now()