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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date function sql statement

Status
Not open for further replies.

bastienk

Programmer
Joined
Mar 3, 2004
Messages
326
Location
CA
Hi All,

I am trying to query a db where I need to get results based on some values. The tricky part is that I need to subtract a number from a data and see if it fits the range.

The current date is sent to the sql statement but the duration value is a column in the db,as is the date_created

Code:
SELECT  *  FROM ads WHERE user_id =1 AND deleted =0 AND ( 2004 -04 -12 - duration )  > date_created

Can I do this? Or should I change my approach and use the date_add function to make the duration field a end date instead?

TIA
 
MySQL won't do date arithmetic using the minus operator. You're going to have to use date_add() or another MySQL function appropriate to your version of MySQL.

Or construct an appropriate date string in PHP and pass that to MySQL. MySQL can compare dates using ">" and "<"

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
so, something like

Code:
SELECT  *  FROM ads WHERE user_id =1 AND deleted =0 AND  DATE_sub('2004 -04 -12', Interval duration )  > date_created

but its not working. Is it the fact the duration is another field in the db?



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top