SQL date format conversion from INT(yyyymmdd) type to date(mm/dd/yyyy)

混江龙づ霸主 提交于 2019-12-30 06:48:15

问题


I have a table with datekey column values(20120728,20120728...) in format of yyyymmdd as int type, I need to make them into date format of mm/dd/yyyy while writing select statement.


回答1:


DECLARE @date int;
SET @date = 20131107

SELECT CONVERT(date, CONVERT(varchar(8), @date), 112)



回答2:


Please Try This

DECLARE @date int;
SET @date = 20120728    
SELECT CONVERT(varchar(20), CONVERT(date, CONVERT(varchar(8), @date), 112),110)as datetime


来源:https://stackoverflow.com/questions/19829818/sql-date-format-conversion-from-intyyyymmdd-type-to-datemm-dd-yyyy

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