0

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!

Matthew J Gravelyn
  • 441
  • 1
  • 4
  • 7
  • Can you add some value that cause the error? – McNets Mar 09 '17 at 19:23
  • Are you asking for the actual date values from the column? I'm not sure which date is causing the error, but I've scanned the column and don't see any weird looking dates. – Matthew J Gravelyn Mar 09 '17 at 19:28
  • I cannot reproduce it. http://dbfiddle.uk/?rdbms=sqlserver_2016&fiddle=a5c9bc6dc009688739f5cb148d58d852 – McNets Mar 09 '17 at 19:41
  • Could this be an issue with the type of SQL installed to the DB? I'm not much for the backend side of things, but I can check with the admin to find out what version we're running. Thanks! – Matthew J Gravelyn Mar 09 '17 at 20:17

0 Answers0