lundi 16 mai 2016

BETWEEN operator not comparing dates correctly in SQL Server 2005

I've got a simple query:

 SELECT *
 FROM TABLE
 WHERE EventDateTime BETWEEN '2016-05-12 00:00:00' and '2016-05-12 23:59:59'

For some reason, the query output includes rows with a datetime of 2016-05-13 00:00:00.

Using CAST to convert the string to datetime removes the values for 2015-05-13:

 SELECT *
 FROM TABLE
 WHERE EventDateTime BETWEEN CAST('2016-05-12 00:00:00' AS DateTime) and CAST('2016-05-12 23:59:59' AS DateTime)

What would cause this?

Aucun commentaire:

Enregistrer un commentaire