Curtis Long
asked on
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??
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??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much!!
One other question.....
What would I add if I wanted it to be current date minus one and minus two etc??
One other question.....
What would I add if I wanted it to be current date minus one and minus two etc??
>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
need to use dateadd function
select dateadd (mm, -1, getdate() ) --will subtract 1 minutes from curent datetime
AND Time_In >= CAST(GETDATE() as date)
-- i dont use the cast(time_in as date)