SQL 2008 R2 Current Date

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??
Curtis LongAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
SELECT blah, blah, blah
FROM blah
WHERE Commodity = 'CULLS'
   AND CAST(Time_In as date) = CAST(GETDATE() as date)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
WHERE Commodity = 'CULLS'
   AND Time_In >= CAST(GETDATE() as date)

-- i dont use the cast(time_in as date)
0
 
Curtis LongAuthor Commented:
Thanks so much!!

One other question.....

What would I add if I wanted it to be current date minus one and minus two etc??
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
>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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.