Ask a Question related to Macromedia ColdFusion, Design and Development.
-
Leonard B #1
cfquery for date not working
Greetings - I am sure what I am missing is something simple. I am trying to
query for a specific date in a database. However, when I search for a specific
date, all I get is a blank page, no error message at all. If i simply output
the entire db records, they all display just fine. Perhaps someone can shed
some light on what really should be a simple straight forward process. DB:
Access 2003 CF: CF5 & CFMX DB Field: StartDate w/ Data Type as Date/Time
(no additional attributes) DB Field: RecordTitle w/ Data Type as Text ====
Query ==== <cfquery name='GetDate' datasource='site_testing_db01'> SELECT
RecordID, StartDate, RecordTitle FROM DateSearch WHERE StartDate = 4/1/2005
<Displays blank page> </cfquery> ==== Output ==== <table width='70%'
border='1' cellpadding='0' cellspacing='0'> <tr> <td
align='center'>Date</td> <td align='center'>Record Title</td> </tr>
<cfoutput query='GetDate'> <tr> <td width='20%'
align='center'>#DateFormat(StartDate, 'mm/dd/yy')#</td> <td
width='80%'>&nbsp;&nbsp;&nbsp;#RecordT itle#</td> </tr> </cfoutput>
</table> Thanks in advance for assistance Leonard B
Leonard B Guest
-
CFQUERY not working for some reason
I have the following code to authenticate a password, and it is successful, complete the <CFIF> Statement: <cfquery name="checkpass"... -
Always Applying Date Mask on cfquery (MySQL)
ColdFusion is displaying my dates in an incorrect timestamp format. I understand that the date can be masked using the DateFormat() function, but... -
PreserveSingleQuotes Not Working in CFQUERY
Just a heads up to those for those using CFSCRIPT within a CFQUERY to compose a Dynamic SQL statement. When you try to use... -
Working w/ Date
:( Hello all, I'm trying to set up a query that gets all the information on tasks that have a due date of today. For some reason the query... -
date command not working in crontab
I have this crontab entered: /usr/local/mysql/bin/mysqldump -u <username> -p<password> --all fg_phpnuke > /usr/local/mysql/var/db-fg_phpnuke`date... -
Kronin555 #2
Re: cfquery for date not working
The problem is that the field you're checking, StartDate, is a Date/Time and
you're just passing it a Date. What you need to do is pull just the date out of
the date/time object in the database.
WHERE to_char(StartDate,'MM/DD/YYYY') = '05/15/2005'
Kronin555 Guest
-
The ScareCrow #3
Re: cfquery for date not working
Not quite true,
The where clause is actually saying
where startdate = 4 divided by 1 divided by 2005
Plus there is no need to convert the date on the db side, just pass it an odbc
date data type
SELECT RecordID, StartDate, RecordTitle
FROM DateSearch
WHERE StartDate = #CreateODBCDate("4/1/2005")#
Ken
The ScareCrow Guest
-
Kronin555 #4
Re: cfquery for date not working
Ken,
You're right on the 4/1/2005, I missed that.
However, your code will do exactly what I said in my original post, which is
compare a field in the database which contains a date and time with a date-only
field (which assumes a time of midnight).
So, if StartDate is 4/1/2005 12:15:03 and you do a search with a date of
4/1/2005, it'll never match because you're comparing 4/1/2005 00:00:00 with
4/1/2005 12:15:03. It is for this reason that I had the
to_char(StartDate,'MM/DD/YYYY') in the query, to pull just the date part out
and ignore the time.
Kronin555 Guest
-
The ScareCrow #5
Re: cfquery for date not working
Kronin555
I totally agree that if the field contains time values, then my code would not
return a match. But if only the date was entered into the field then it will
always have a time value of "00:00:00". Which I would recommend unless a time
value is absolutly required. If the field does have a time value then other
methods need to be used.
As for your solution, I would be very careful with this method, as the the
date passed hs to be in the exact format as the to_char format. But again I
would not use the to_char function. I would use the DATEVALUE(date_text)
function.
But as I was taught that dates should always stay as dates, I never convert
them when quering only for display. It just creates extra processing and
possible bugs.
Ken
The ScareCrow Guest
-
OldCFer #6
Re: cfquery for date not working
There's a couple of reasons not to use DB date to string conversions. First, the
DB has to convert every date in each row to a string to compare it to the
value
passed. Its much more efficient if it can compare the date value passed, to
the
stored dates directly. The other reason is that using DB functions makes the
code less portable since the functions are usually specific to that DB.
OldCFer Guest
-
Leonard B #7
Re: cfquery for date not working
Greetings - Found a working solution to situation in the Macromedia ColdFusion
5 - Web Application Construction Kit Book - Ben Forta and Nate Weiss. WHERE
StartDate >= #CreateODBCDate(form.DateSearch)# AND StartDate <
#CreateODBCDate(DateAdd('d',form.DateSearch, 1))# Thanks for the input, took
note of what you guys provided, and added to my resource records. Leonard
Leonard B Guest



Reply With Quote

