I’m getting the following error when trying to convert a varchar to datetime in sql server.
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Here are the ResponseDate column values:
2012-06-19 10:30:36.157
2012-06-19 10:30:36.157
2012-07-09 11:37:14.287
2012-06-21 10:15:06.733
2012-07-02 13:19:13.080
I’m trying to write a query that selects * in july.
Select * From table WHERE CONVERT(datetime,ResponseDate) BETWEEN '20120631' AND '20120801'
I thought there wouldnt be any issues because the varchar is already in datetime format.
Can anyone give me advice? Thanks!
Try using the following modified statement. I believe the issue is that it’s trying to convert your strings in the WHERE clause to a DateTime implicitly but they aren’t in a format where it can.