SELECT statement with date expression

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I got a table with the following fields:

BirthDay (Date)
Reminder (Short integer)

I need to select all records where BirthDay - Reminder <= Today to display a

In Access and MS SQL, I can do this:

SELECT ..... WHERE BirthDay - Reminder <= 01/01/2006

assuming 01/01/2006 is today's date.

Access and MS SQL can substract a number (Reminder) from BirthDay.

Can someone please tell me how I can achieve the same SELECT in MySQL?

Any help greatly appreciated.


Re: SELECT statement with date expression

zMisc wrote:
Quoted text here. Click to load it

First you need to convert that string into correct date format
yyyy-mm-dd so it would be 2006-01-01.

Then you need '' characters around the date '2006-01-01'

But if you are really using the current date, you can use curdate()
function instead of the '2006-01-01' to get the current date.

Then see the first example in this page how to subtract certain amount
of days (or other units) from a date:

Re: SELECT statement with date expression

Quoted text here. Click to load it

Read about the functions DATE_ADD() and DATE_SUB() on this page:

MySQL also supports ANSI SQL syntax for date arithmetic, for example:

    WHERE BirthDay - INTERVAL Reminder DAY <= '2006-01-01'

Note that MySQL date constants are strings, so must be in single-quotes, and
they must be in YYYY-MM-DD format.

Bill K.

Site Timeline