CK knows Wayne

Easy machine readable date formats with MS SQL Server

Published at by Christian Kruse, updated at
Filed under: ms, sql, server, date, datetime, machine, readable

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.

Hey, two comments!

Comment Feed: RSS / Atom

Your Comment

You can use MarkDown to format your comment: *Word* for italic, **Word** for bold, images will get removed.




Because of massive spam attacks you may only post if you can answer the following question: