Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple date query I can't do

Status
Not open for further replies.

warby1212

Programmer
Joined
Jun 9, 2003
Messages
183
Location
AU
Hi,

I'm new to Mysql so this is probably pretty obvious but can't find a simple answer in docs.

I have data in column formatted as DATE and want to select rows where date (column is called "birth") is 40 days from the current date.

Any help appreciated :)

Way away in Australia
 
How about:[tt]

SELECT *
FROM tbl
WHERE birth = CURDATE() - INTERVAL 40 DAY[/tt]


Or, if you mean 40 days after the current date, change the minus to a plus.


-----
ALTER world DROP injustice, ADD peace;
 
Thank you guys. I haven't replied because I'm trying to make it work between a thousand other things. thanks again will let you know.

Way away in Australia
 
so you want 40 days notice on someones brithday ?



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
That's right. It's just for my home page on my own PC. I still can't get it to work. The helpful people above answered my wrong question, correctly. (I've realized) 40 days before the person's birth is actually no help, what I need is 40 days before their birthday this year. So it needs to be relative to the month part of the the DATE data. Any help?

Way away in Australia
 
Found it. I must learn to pester Google before people.
Thanks all :)

SELECT name, birth FROM birthdays WHERE MONTH(birth) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH))

Way away in Australia
 
Thats the way ! :-)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top