Working with Format Sql server 2012 features.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 315
FORMAT Method is just like .Net String.Format method ,used for formatting date,string or any data type value.
SELECT Format(GETDATE(),'MM/dd/yyyy');

Output:-09/30/2014
SELECT FORMAT(Cast('123456789' AS int),'000-00-0000') AS SSN 

Output:-123-45-6789
SELECT FORMAT(Cast('1234567890' AS int),'(000)-000-0000') AS PHONE_NUMBER 

Output:-(123)-456-7890
SELECT FORMAT(GETDATE(),'d','en-US') AS USShortDate; 

Output:-7/9/2014
SELECT FORMAT(GETDATE(),'d','nl-NL') AS DutchShortDate;

Output:-9-7-2014
SELECT FORMAT(GETDATE(),'D','en-US') AS USLongDate;

Output:-Wednesday, July 9, 2014

Comments or Responses

Login to post response