SELECT based on date value

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

SELECT based on date value

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: SELECT based on date value

Post 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?
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Re: SELECT based on date value

Post 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
Post Reply