Check dates are valid in sql

Tearing my hair out over a query that involves manipulating and querying dates from SQL. Amongst various stuff I came across was this useful little snippet, if you have stored dates in a text field (eg nvarchar) it can tell you if the dates are valid:

set dateformat mdy

select *
from t
where isdate(startdate) = 1
    and convert(datetime, startdate) not between '19000101' and '20790606'

Keeping this one in the toolbox for another day.

Leave a comment