如何在 SQL Server 2008 中将 int 转换为日期 [英] How to convert int to date in SQL Server 2008
本文介绍了如何在 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)
干杯
这篇关于如何在 SQL Server 2008 中将 int 转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文