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? Link to comment https://forums.phpfreaks.com/topic/286260-more-than-a-month-old/ Share on other sites More sharing options...
xProteuSx Posted February 17, 2014 Author 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. Link to comment https://forums.phpfreaks.com/topic/286260-more-than-a-month-old/#findComment-1469241 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.