jeudi 1 septembre 2016

Dealing with out of range value on varchar date conversion

I'm attempting to convert dates input in our system as text in the format YYYYMMDD into dates. Unfortunately our system allows the use of the 31st of any month to signify that it's the last day of the month that's important, for some functions like interest accrual etc.

I have a date showing as 20160931 which obviously fails to convert via CONVERT(Datetime, CONVERT(Char(8), [FIELD])) and throws the out-of-range value error.

How can I overcome this, so that I can convert it to the correct value, in this case 30/09/2016.

Aucun commentaire:

Enregistrer un commentaire