Page 1 of 1

SELECT based on date value

Posted: Sat Apr 19, 2008 10:51 am
by evilchris2003
Hi everyone

Im trying to structure a query for my website which selects the users whose membership is nearing expiry and I cant get it to work. Im not sure where im going wrong

Code: Select all

SELECT * FROM Customers WHERE member_level='full' AND expiry_date < ADDDATE(NOW(), INTERVAL 32 DAY)
Above is the query and that is exactly what queries the database (I copied and pasted from the web page using 'echo' so I could see what was going on server side)
Why does the ADDDATE function work for an INSERT (I have it working for this elsewhere) but not a SELECT ?

Any help is always appreciated

Thanks in advance as always
EC

Re: SELECT based on date value

Posted: Sat Apr 19, 2008 9:30 pm
by flying_circus
I'm not sure, but doesnt NOW() return a unix timestamp? The MySQL Documentation shows adddate() working in a select statement, so I would assume that's ok.

Try the DATE() or DATE_FORMAT() functions

http://dev.mysql.com/doc/refman/5.0/en/ ... on_adddate

What do you mean by "I cant get it to work"? Does it return a SQL error or just not the expected results?

Re: SELECT based on date value

Posted: Sun Apr 20, 2008 9:38 am
by evilchris2003
Thanks Ill hae a look at the link by not get it to work it simply returns nothing
I have and 'if' statement which displays a layout in a simple table format if there are no results there is a simple message saying no results match blah blah

What I get when I run the query is the table with no results so I know that it is matching the 1 test record that will match what im asking but it isnt actually printing any results which I find very strange indeed