Muad'Dib
Muad'Dib

Reputation: 520

SQL Count based on time

I have thousands of customers orders. I just need a count of all orders placed after 5:00 PM going back to the very first entry. How would I query this?

SELECT COUNT(OrderID) AS TotalOrders
FROM Nop_Order
WHERE (CreatedOn > '???')

Upvotes: 3

Views: 326

Answers (2)

Standage
Standage

Reputation: 1517

SELECT COUNT(OrderID) AS TotalOrders
from Nop_Order where datepart(hh, CreatedOn) > 17

Upvotes: 1

Michael Fredrickson
Michael Fredrickson

Reputation: 37398

You'll want to use the DATEPART function to isolate just the time component of the date, and compare it to 17, which would be 5:00 PM in military time...

SELECT COUNT(OrderID) AS TotalOrders
FROM Nop_Order
WHERE (DATEPART(HOUR, CreatedOn) >= 17)

Upvotes: 5

Related Questions