Solved

Returning a query with #now()#

Posted on 2013-01-03
5
257 Views
Last Modified: 2013-01-03
Experts-

I'm having some trouble returning results from a query.  I am using SQL server 2008 and the field (enterDate) is set as a dateTime in the table.  When I run the query below, it does not return any records although there are records in the DB that should be returned.  Any suggestions would be appreciated.  EnterDate field in the db looks like this....
2013-01-03 09:51:09.613


<cfquery name="getBillable" datasource="#application.dsn#">
    select *
    from prospects
    where email = '#form.email#'
    and enterDate = #dateFormat(now(),'yyyy-mm-dd')#      
</cfquery>

Thanks
Nick
0
Comment
Question by:nmarano
5 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 38740303
why not set the date as a variable before the query then pass the variable into the query.
0
 
LVL 4

Accepted Solution

by:
JohnHowlett earned 250 total points
ID: 38740307
Then you will need the exact time as well as the date!!

Otherwise:

   select *
    from prospects
    where email = '#form.email#'
    and enterDate > [original date]  AND enterDate < [orginal date plus 1 day]


Or you can use the SQL BETWEEN statement.
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 38740327
Once you do that I would use a comparative instead of "="   as that is expecting the exact same value, if you are planning to check for date time to the second then be sure to assign that in your statement as you are asking for

Row value = Variable

If you are looking for a period then you are better off looking in a window vs time to the second.
0
 
LVL 2

Author Closing Comment

by:nmarano
ID: 38740388
Thanks for your help
0
 
LVL 52

Expert Comment

by:_agx_
ID: 38740460
>   and enterDate > [original date]  AND enterDate < [orginal date plus 1 day]

Small typo. I think he meant  ">= [original date]" rather than "> [original date]"

Edit: That approach works well.  Using cfqueryparam it is a simple as:

    WHERE enterDate >= <cfqueryparam value="#now()#" cfsqltype="cf_sql_date">
    AND      enterDate < <cfqueryparam value="#dateAdd('d', 1, now())#" cfsqltype="cf_sql_date">
    ...
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I have multiple sites sharing the same codebase? 10 67
cfgrid format issue and columns missing 4 109
Coldfusion Report Builder HTML table 2 69
Managing DSNs in CF 11 5 22
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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