从日期时间中删除分钟 - sql [英] Remove minutes from datetime - sql

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

问题描述

DECLARE @MinutesToAdd int = 20; 
DECLARE @StartTimeDate datetime = '2017-06-05 14:37:56.113';  
DATEADD(minute,@MinutesToAdd,@StartTimeDate);

上面的代码将 20 分钟添加到 StartTimeDate.有没有好办法去掉那些20分钟不加的?试图找到解决方案,但没有找到.有什么想法吗?

Code above adds 20 minutes to StartTimeDate. Is there a good way to remove those 20 minutes not add? Tried to find a solution, but didn't catch one. Any ideas?

推荐答案

您没有任何特定的函数来减去任何日期部分

You don't have any specific function to subtract any dateparts

前面加负号

Select DATEADD(minute,-@MinutesToAdd,@StartTimeDate);

或乘以-1

Select DATEADD(minute,@MinutesToAdd * -1 ,@StartTimeDate);

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

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