Solved

ColdFusion Mysql date query problems

Posted on 2003-11-13
6
709 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Crazee
ID: 9743430
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
ID: 9744606
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
ID: 9745247
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 12

Expert Comment

by:jyokum
ID: 9745475
hmm??
0
 
LVL 2

Expert Comment

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

Expert Comment

by:Crazee
ID: 9745550
or rather no more than...
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

726 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