DatabaseDevelopmentT-SQL

Will not get stuck in date formatting again

banging_head_smallYou’ve all been there, you’ve all banged your head against the monitor just because you could not remember that code for the specific date-format you needed. I know I have.

I SQL 2012 this is no longer such a headake to remember all those codes – JAY!

Ex. from SQL 2008 R2 and older:

SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY] --Italian
SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY] --German
SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] --USA

And with the codes specific for each country format needed.

 

Now in SQL 2012 we are all free to try to memorize those codes for each country – all you need now is the countrys letters and language. For those of you who are familiar with Reporting Services ‘locale’ setup, this is easy-peasy.

There the same formats in SQL 2012:

SELECT FORMAT(getdate(), N'd', N'lt-lt'), --Italian
SELECT FORMAT(getdate(), N'd', N'de-de'), --German
SELECT FORMAT(getdate(), N'd', N'en-us') --USA

I know that my everyday coding just got a whole lot smoother and easier.

The complete documentation from Microsoft is here.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *