[英]SQL Subtract Time from a DateTime
I have two fields of data, 'CreatedDate' datetime (eg. 2013-11-06 1:00:00.000) and another is 'TimeToLive' time(7) (eg. 01:00:00) 我有两个数据字段,“ CreatedDate”日期时间(例如2013-11-06 1:00:00.000),另一个是“ TimeToLive”时间(7)(例如01:00:00)
I would like to check if the created date is more than an hour past the current time 我想检查创建的日期是否比当前时间晚一个小时以上
I have tried DATEADD(hour, - (TimeToLive), GETDATE()); 我已经尝试过DATEADD(hour,-(TimeToLive),GETDATE()); and various implementation doing a convert to datetime to get the adjusted datetime but no success overall
以及各种执行转换为datetime以获得调整后的datetime但总体没有成功的实现
SELECT DATEADD(hour, -DATEPART(hour, TimeToLive), GETDATE());
如果需要,您可以展开以减去其他日期部分(分钟,秒)。
如果您使用的是Oracle,则可能需要签出NUMTODSINTERVAL功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.