Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

While exploring the new function FORMAT I have come across the following issue, would like to know if any one else has faced a similar problem and found the fix for this, or if it is a bug?

SELECT FORMAT(GETDATE(),'mm/dd/yyyy','en-US');
SELECT GETDATE();

Output:

  1. 02/02/2013
  2. 2013-06-02 12:02:54.067
share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

The Format function argument is a .net format string, where mm is minutes and MM is months. You specified minutes, so minutes is what you got.

There are example format strings at Standard Date and Time Format Strings. As an alternative to MM/dd/yyyy you can also use just d which is the Short Date Format specifier (detailed on the linked page).

share|improve this answer
    
+1 for a more comprehendible answer than mine :) –  Justicator Jun 2 '13 at 10:22
    
+1 but note that if you use d you lose leading zeros. –  Aaron Bertrand Jun 2 '13 at 21:06
add comment

The FORMAT function is case sensitive
As such, "mm" stands for minutes and "MM" stands for month.

You can see a complete table of combinations and letter meanings here. This is the .NET article for date and time formatting, which SQL Server's FORMAT is using.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.