Solved

ColdFusion Mysql date query problems

Posted on 2003-11-13
6
701 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:BLWedge
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Crazee
Comment Utility
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
0
 
LVL 12

Expert Comment

by:jyokum
Comment Utility
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>
0
 
LVL 17

Accepted Solution

by:
anandkp earned 250 total points
Comment Utility
yes - cfqueryparam shld do it for u !

if u want all the records in the DB for last 30 days ...

<cfquery name="x">
SELECT field FROM table
WHERE due_date > <cfqueryparam value="#DateAdd('d',-30,now())#" cfsqltype="cf_sql_date">
</cfquery>
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:jyokum
Comment Utility
hmm??
0
 
LVL 2

Expert Comment

by:Crazee
Comment Utility
Strange... you specified "30 days older than today", not at least 30 days older...
0
 
LVL 2

Expert Comment

by:Crazee
Comment Utility
or rather no more than...
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now