I've seen plenty of threads about datetime2 overflows when hitting the minimum date, but I don't have that in my data. Additionally, the DATEADD
works fine in the SELECT
statement, but not in the WHERE
statement. Here's what I'm trying to do:
SELECT DATEADD(hour, -8, MyDate) as 'PST Date'
FROM [dbo].[MyTable]
WHERE DATEADD(hour, -8, MyDate) between '2017-01-01' and '2017-02-01'
Which resolves to:
Adding a value to a 'datetime2' column caused an overflow.
This query works just fine if I take out the DATEADD
from the WHERE
statement, but then I'm getting an 8-hour shift in my results. Any idea why this is happening or what I can do to make the WHERE
work properly? Thanks!