Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/302739-selecting-all-inactive-users/
Share on other sites

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.