Save Ukraine

Easy machine readable date formats with MS SQL Server

Christian Kruse,

The last few hours I was looking for a method to make the date and datetime data types easier machine readable and more predictable in string representation. There are two things you have to do:

  1. The first thing is to select the correct language environment, just to be sure. I my case this is english: SET LANGUAGE english. This ensures, that the „natueral representation“ is always the same.
  2. The second thing is: you have to type cast the date/datetime field via CONVERT(): CONVERT(char(19),DateTimeField,120) AS DateTimeField for datetime fields and CONVERT(char(10),DateField,103) AS DateField for date-only fields.

Kind of fucked up, but if you have to use MS SQL Server you are used to fucked-up solutions.