Will not get stuck in date formatting again

Date formattingYou’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 formatting you needed in SQL. I know I have.

I SQL 2012 this is no longer such a headache 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.

Få besked om næste indlæg

Skriv dig gerne op til at modtage en mail, ved næste indlæg. Det kan du gøre nedenfor.



Marketing stuff

Our emails contain marketing stuff, so we need to give you some fine quality fine print: brianbonk will use the information you provide on this form to email you with updates and marketing. You can change your mind at any time by clicking the unsubscribe link in the footer of any email you receive from us, or by contacting us at help@brianbonk.dk. We use Mailchimp as our marketing platform. By checking the box to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing, and that we may process your information in accordance with these terms.

Følg mig på Instagram

Leave a Reply

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

en_USEnglish