Solved

Returning a query with #now()#

Posted on 2013-01-03
5
261 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
[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
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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

635 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