简体   繁体   中英

Php query for logged in users and not logged in users between two dates

i am trying to query which shows all active users (Logged in Users) between two dates. When ever a user logs in the date is recorded in last_login field. The query is below and its working fine;

select * from users where (users.last_login BETWEEN '" . $fromdate . "' AND  '" . $todate . "')

Now i am trying to query which shows all Inactive Users (Not Logged in Users) between two dates. I am not sure how i will modify the existing query to achieve this condition. Can anyone pls help me on this.

If you are asking how to write the inverse logic, I think this will do the job:

"SELECT * FROM users WHERE last_login NOT BETWEEN '" . $fromdate . "' AND '" . $todate . "'"

*note if these variables are coming from user input, you should be using prepared statements and placeholders for security/stability.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM