Solved

ColdFusion Mysql date query problems

Posted on 2003-11-13
6
706 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Suggested Solutions

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
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 add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

730 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