DATETIME with different formarts + SQL Server 2012

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 287
FORMART function is used to format datetime values to display in many formats..


-- Using FORMAT to display Datetime Data type
DECLARE @todaydate datetime = GETDATE()
SELECT FORMAT(@todaydate,'d ') AS 'Short date pattern' -- 3/23/2015
SELECT FORMAT(@todaydate,'d','en-IN' ) AS 'Short date pattern with culture' -- 23-03-2015
SELECT FORMAT(@todaydate,'D' ) AS 'Long Date pattern' -- Monday, March 23, 2015
SELECT FORMAT(@todaydate,'T' ) AS 'Long Time pattern' -- 3:34:40 PM
SELECT FORMAT(@todaydate,'ddd ') AS 'Custom Day Pattern' -- Mon
SELECT FORMAT(@todaydate,'MMM ') AS 'Custom Month Pattern' -- Mar
SELECT FORMAT(@todaydate,'yyyy ') AS 'Custom Year Pattern' -- 2015
SELECT FORMAT(@todaydate,'MM-dd-yy ') AS 'Custom date display Pattern' -- 03-23-15

Comments or Responses

Login to post response