1

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
7

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).

  • +1 but note that if you use d you lose leading zeros. – Aaron Bertrand Jun 2 '13 at 21:06
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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