doctor_james Posted January 12, 2008 Share Posted January 12, 2008 Hi . How can I get those records which are older less than a month ? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/85688-sql-query/ Share on other sites More sharing options...
toplay Posted January 12, 2008 Share Posted January 12, 2008 Your "older less" seems contradictory. Below, I'm assuming you want rows that are older than a month ago based on a date_column of type DATE (not DATETIME). SELECT * FROM table_name WHERE date_column < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) See manual: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-sub Sometime you'll see people post just the ' - INTERVAL 1 MONTH', but that only works with certain versions of MySQL, so my example uses the DATE_SUB() function since I don't know the version of your MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/85688-sql-query/#findComment-437368 Share on other sites More sharing options...
fenway Posted January 12, 2008 Share Posted January 12, 2008 Sometime you'll see people post just the ' - INTERVAL 1 MONTH', but that only works with certain versions of MySQL, so my example uses the DATE_SUB() function since I don't know the version of your MySQL. This "date arithmetic" functionality was added in v3.23 -- I seriously hope no one is using anything prior to that release (or that release, for that matter). So it's quite safe to use; and IMHO much easier to read without extra parens. Quote Link to comment https://forums.phpfreaks.com/topic/85688-sql-query/#findComment-437519 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.