SQL 2008 R2 Current Date

Posted on 2012-09-11
Last Modified: 2012-09-11
I run this query to give me all the culls we have since 8-1-2012

SELECT     Ticket_Number, Time_In, Time_Out, Customer, Commodity, Driver, Lot, Gross, Tare, Field_Id, Truck_Id
FROM         dbo.[Transaction]
WHERE     (Commodity = 'CULLS') AND (Time_In >= CONVERT(DATETIME, '2012-08-01 00:00:00', 102))

How can I change this soi instead it would deliver all CULLS for the current date only??
Question by:HDM
    LVL 65

    Accepted Solution

    SELECT blah, blah, blah
    FROM blah
    WHERE Commodity = 'CULLS'
       AND CAST(Time_In as date) = CAST(GETDATE() as date)
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    WHERE Commodity = 'CULLS'
       AND Time_In >= CAST(GETDATE() as date)

    -- i dont use the cast(time_in as date)

    Author Closing Comment

    Thanks so much!!

    One other question.....

    What would I add if I wanted it to be current date minus one and minus two etc??
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    >What would I add if I wanted it to be current date minus one and minus two etc??
    need to use dateadd function

    select dateadd (mm, -1, getdate() )  --will subtract 1 minutes  from curent datetime

    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

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( 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…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now