By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

SELECT statement with date expression

P: n/a
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
reminder.

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.

Tks
John
Feb 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
zMisc wrote:
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
reminder.

In Access and MS SQL, I can do this:

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

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


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:
http://dev.mysql.com/doc/refman/5.0/...functions.html
Feb 4 '06 #2

P: n/a
"zMisc" <yo********@hotmail.com> wrote in message
news:Lb********************@news-server.bigpond.net.au...
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?


Read about the functions DATE_ADD() and DATE_SUB() on this page:
http://dev.mysql.com/doc/refman/5.0/...functions.html

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.

Regards,
Bill K.
Feb 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.