如何在 SQL Server 2008 中将 int 转换为日期
问题描述:
我使用的是 MS SQL Server 2008,在一个表中,我将列 idate 作为日期,但采用整数格式.但在查询中,我希望采用日期格式.是否可以将整数日期转换为正确的日期时间格式?
I am using MS SQL Server 2008, and in a table I have column idate as date but in the integer format. But in the query I want that in the date format. Is it possible to convert integer date into proper datetime format?
答
您不能将整数值直接转换为日期,但可以先将其转换为日期时间,然后再转换为日期类型
You can't convert an integer value straight to a date but you can first it to a datetime then to a date type
select cast(40835 as datetime)
然后转换为日期(SQL 2008)
and then convert to a date (SQL 2008)
select cast(cast(40835 as datetime) as date)
干杯