sql server中 datetime转int的语句

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql server中 datetime转int的语句相关的知识,希望对你有一定的参考价值。

请问``在sql server中`` 我要将datetime日期格式转换成int日期格式``并且显示到秒``  SQL语句怎么写`` 我写出来的只是显示到天`` 语句如下:declare   @d  datetimeset   @d= '2009-5-22' select convert(int,cast(@d as datetime))

参考技术A declare @d datetimeset @d= '2009-5-22' select convert(int,cast(@d as datetime),120)本回答被提问者采纳 参考技术B select datediff(second,'1970-01-01',@d)

SQL Server中DateTime与DateTime2的区别

DateTime字段类型对应的时间格式是yyyy-MM-dd HH:mm:ss.fff,3个f,精确到1毫秒(ms),示例2014-12-0317:06:15.433。

DateTime2字段类型对应的时间格式是yyyy-MM-dd HH:mm:ss.fffffff,7个f,精确到0.1微秒(μs),示例2014-12-0317:23:19.2880929。

如果用SQL的日期函数进行赋值,DateTime字段类型要用GETDATE(),DateTime2字段类型要用SYSDATETIME()。

以上是关于sql server中 datetime转int的语句的主要内容,如果未能解决你的问题,请参考以下文章