Link to home
Start Free TrialLog in
Avatar of BLWedge
BLWedge

asked on

ColdFusion Mysql date query problems

Ok.  I have a table in Mysql that has a field that is a date datatype named due_date.  As you probably already know, Mysql date fields store dates in the format yyyy-mm-dd.  I need to run a query from coldfusion that finds dates in this field that are 30 days older than today.  In coldfusion now() - 30 should accomplish this.  I can't seen to get the query right to accomplish this.  I have done this in Oracle before but the date field in Oracle is formatted differently.  I need to know how to structure this query.
Avatar of Crazee
Crazee

SELECT field FROM table WHERE due_date = '#DateFormat( DateAdd( 'd' , -30 , now() ) , 'yyyy-mm-dd' )#'
( perhaps you don't have to enclose date in single quotes )

or use sql's DATEADD - this is Ms-SQL how ever, so the function may differ...

SELECT field FROM table WHERE due_date = DATEADD( Day , -30 , getDate() )

cheers
CFQUERYPARAM usually solves most date/time problems with databases

<cfquery ...>
SELECT field FROM table WHERE due_date = <cfqueryparam value="#DateAdd('d',-30,now())#" cfsqltype="cf_sql_date">
</cfquery>
ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hmm??
Strange... you specified "30 days older than today", not at least 30 days older...
or rather no more than...