how to format getdate into YYYYMMDDHHmmSS

后端 未结 7 1536
春和景丽
春和景丽 2021-02-19 04:50

In SQL Server how do I format getdate() output into YYYYMMDDHHmmSS where HH is 24 hour format?

I\'ve got the YYYYMMDD

7条回答
  •  余生分开走
    2021-02-19 05:42

    Just for anyone searching for this functionality that has SQL Server 2012 you can use the FORMAT function:

    SELECT FORMAT ( GETDATE(), 'yyyyMMddHHmmss') AS 'Custom DateTime'
    

    This allows any .NET format strings making it a useful new addition.

提交回复
热议问题