Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Count based on time

Tags:

sql

t-sql

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 > '???')
like image 599
Muad'Dib Avatar asked Mar 15 '26 00:03

Muad'Dib


2 Answers

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)
like image 154
Michael Fredrickson Avatar answered Mar 17 '26 17:03

Michael Fredrickson


SELECT COUNT(OrderID) AS TotalOrders
from Nop_Order where datepart(hh, CreatedOn) > 17
like image 35
Standage Avatar answered Mar 17 '26 17:03

Standage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!