xProteuSx Posted February 17, 2014 Share Posted February 17, 2014 I am extremely unfamiliar with date comparisons in MYSQL. I've googled it, and I cannot find anything (though I am sure there must be something out there) that works for my particular situation. Here it is: I have a 'timestamp' field in my database. The format of the field is like this: 2014-02-17 05:39:32 Now, I am trying to find all entries that are less than a month old. Here is what I have been able to find, but have not been able to make work: SELECT * FROM my_table WHERE tbl_time < date_sub(now(), interval 1 month); It does not seem to matter where I have either of these: SELECT * FROM my_table WHERE tbl_time < date_sub(now(), interval 1 month); SELECT * FROM my_table WHERE tbl_time > date_sub(now(), interval 1 month); Both of these queries return the same results. How can this be? Quote Link to comment Share on other sites More sharing options...
Solution xProteuSx Posted February 17, 2014 Author Solution Share Posted February 17, 2014 Of course, I figure it out 3 minutes later ... SELECT * FROM my_table WHERE DATE(tbl_time) > date_sub(now(), interval 1 month); Turning tbl_time, the timestamp, into a date made it all work. Cheers. Quote Link to comment 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.