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
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
Share on other sites

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.