如何从SQL中的DateTime列中减去时间列? [英] How to subtract Time Column from DateTime Column in SQL?

查看:145
本文介绍了如何从SQL中的DateTime列中减去时间列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个Crea_Date列,它是一个DateTime列。我想从crea_date列中减去IST列中的值,并返回一个包含DateTime值的新列。我的样本数据是这样的:



Hi,
I have Crea_Date column which is a DateTime Column. I want to subtract the value in the IST column from crea_date Column and return a new column with the DateTime Value in it. My sample data is like this:

States  crea_date       IST
AB  2014-12-30 15:01:00.000 12:30:00.0000000
AK  2014-12-29 16:32:00.000 10:30:00.0000000
AZ  2014-12-18 16:07:00.000 11:30:00.0000000

Thanks in Advance

推荐答案

据我所知,没有其他内置方法但要使用DATEPART从时间字段中提取小时,分钟和秒,并使用DATEDADD从原始字段值中减去这些值。它不是一个很好的公式,但会起作用。
As I know there is no other built-in method but to used DATEPART to extract hour, minute and second from the time field and use DATEDADD to substract these values from the original field value. It won't be a nice formula, but will work.


请检查这是否有效

http://stackoverflow.com/questions/13759278/how-can-i-subtract-6-hour-from当前时间 [ ^ ]



http://stackoverflow.com/questions/3993226/c-whats-the-easiest-way-to-subtract-time [<一个href =http://stackoverflow.com/questions/3993226/c-whats-the-easiest-way-to-subtract-timetarget =_ blanktitle =New Window> ^ ]



这两个链接都建议使用DateTime.Add(TimeSpan)方法作为解决方案。
Please check whether this works
http://stackoverflow.com/questions/13759278/how-can-i-subtract-6-hour-from-the-current-time[^]

http://stackoverflow.com/questions/3993226/c-whats-the-easiest-way-to-subtract-time[^]

Both these links recommending to use DateTime.Add(TimeSpan) method as a solution.


这篇关于如何从SQL中的DateTime列中减去时间列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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