dean7 Posted December 14, 2016 Share Posted December 14, 2016 Hey guys, just a quick question, I'm wanting to select all the inactive users from the database who have been inactive for like 2 years, 3 years, 4 years etc from their last login but how would I go by doing this? I mean I'm guessing you would get all the users which are < the date posted but I'm unsure how I can get the results to what I'm after? Any help is appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/302739-selecting-all-inactive-users/ Share on other sites More sharing options...
requinix Posted December 14, 2016 Share Posted December 14, 2016 Huh? The results you want are the inactive users, and the query you described will return the inactive users. Where's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/302739-selecting-all-inactive-users/#findComment-1540326 Share on other sites More sharing options...
dean7 Posted December 14, 2016 Author Share Posted December 14, 2016 I didn't explain it very well. Let me try again, I'm coding a page to show users who haven't logged in for so many years (2,3,4,5 years etc). In my database I'm holding the last login like this: 14th Dec 16, 16:00. How would I do a query to select all the users from the year posted? Hope this is slightly clearer Quote Link to comment https://forums.phpfreaks.com/topic/302739-selecting-all-inactive-users/#findComment-1540328 Share on other sites More sharing options...
Barand Posted December 14, 2016 Share Posted December 14, 2016 You can't do correct comparisons on dates in that format (for example 15th Dec 15 > 14th Dec 16 whereas you need it to be less than). Always store dates in a database as yyyy-mm-dd format (type DATE, DATETIME or TIMESTAMP). To make it usable you have the overhead of using STR_TO_DATE() function to do a compare in a query. Quote Link to comment https://forums.phpfreaks.com/topic/302739-selecting-all-inactive-users/#findComment-1540331 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.