I have selected rows based on DateTime before using either:
DATEADD(day, -1, GetDate()) AND GETDATE()
to get the latest record since yesterday, and
DECLARE @today DATETIME = CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)
DATEADD(mi, 00, DATEADD(hh, 8, @today)) AND DATEADD(hh, 9, @today)
In order to get a row that was between a certain time frame from the current day. Now I have a table that has a separate time and date column, so both of these do not work. I always get an error when I try either of the above methods saying:
“The data types time and datetime are incompatible in the greater than or equal to operator.” I know the problem is that I don’t have a DateTime type column to reference. Is there a way to get a row between a certain time frame referencing separate time and date fields? Thanks
You can add the Date and the Time fields together to create a single date/time field with which to compare:
So provided your
DATEADD()is setup correctly, you could do this: