SQL Server 从日期时间中删除毫秒 [英] SQL Server remove milliseconds from datetime

查看:92
本文介绍了SQL Server 从日期时间中删除毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select *
from table
where date > '2010-07-20 03:21:52'

我希望不会给我任何结果......除了我得到一个日期时间为 2010-07-20 03:21:52.577

which I would expect to not give me any results... EXCEPT I'm getting a record with a datetime of 2010-07-20 03:21:52.577

如何让查询忽略毫秒?

推荐答案

你只需要找出日期的毫秒部分并在比较之前减去它,就像这样:

You just have to figure out the millisecond part of the date and subtract it out before comparison, like this:

select * 
from table 
where DATEADD(ms, -DATEPART(ms, date), date) > '2010-07-20 03:21:52'

这篇关于SQL Server 从日期时间中删除毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆