Convert Date to CYYMMDD SQL-Server

左心房为你撑大大i 提交于 2020-01-05 04:10:07

问题


I am interested in converting a date value to CYYMMDD using native SQL Server 2012 functions.

I checked here:

http://www.sql-server-helper.com/tips/date-formats.aspx

and couldn't find anything.

Anyone know?

C stands for century I guess...


回答1:


Have you looked at the new FORMAT function in SQL Server 2012?

http://msdn.microsoft.com/en-us/library/hh213505.aspx

You should be able to use something like this:

SELECT FORMAT(YourDateColumn, 'yyyyMMdd')

or whatever you really want to use - basically, the same formatting options as in C# / .NET are available when using FORMAT



来源:https://stackoverflow.com/questions/24292797/convert-date-to-cyymmdd-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!