Easy machine readable date formats with MS SQL Server
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:
- 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. - 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 andCONVERT(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.