Jump to content

SQL query.


doctor_james

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/85688-sql-query/#findComment-437368
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/85688-sql-query/#findComment-437519
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.