Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

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 Long
Curtis Long
  • 2
1 Solution
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)
Aneesh RetnakaranDatabase AdministratorCommented:
WHERE Commodity = 'CULLS'
   AND Time_In >= CAST(GETDATE() as date)

-- i dont use the cast(time_in as date)
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??
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now