Solved

Returning a query with #now()#

Posted on 2013-01-03
5
253 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 28

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 28

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

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!

Join & Write a Comment

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

12 Experts available now in Live!

Get 1:1 Help Now