Column utc time created
is a datetime
field of when entry was made in a table that's updated hourly. Contains 24 entries for each day.
I want to query for same time of day across a set of days (might want all 4pm records for 10/1-10/10) but don't want records for other times in that date range. I don't want all 4pm records in the table (the whole month is in the table).
How to do this?
CodePudding user response:
Just filter by date and then hour:
SELECT
*
FROM
TableName
WHERE
CAST(UTCTimeCreated AS DATE) BETWEEN '2022-10-01' AND '2022-10-10'
AND HOUR(UTCTimeCreated) = 16 -- or whatever
CodePudding user response:
Similar to what John K. have (SQL):
SELECT
*
FROM
TableName
WHERE
UTCTimeCreated BETWEEN '2022-10-01' AND '2022-10-10' AND DATEPART(Hour,UTCTimeCreated ) = 16