-2

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

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
sv.sasi
  • 7
  • 4

3 Answers3

0

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.

Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
0

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
oussama abdou
  • 317
  • 1
  • 7
0

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()
Vamshi .goli
  • 522
  • 4
  • 13