如何在T-SQL中添加两个日期值 [英] How to Add Two Date Values in T-SQL
问题描述
我有一个系统,它在一个单独的字段中存储日期值(Date1)和时间值(From Time),我需要使用完整的日期/时间结果(FromDT)。如何将这两个值一起添加,因为这似乎不受T-SQL的支持?
我还有其他时间字段([To Time]& [Break])允许除非[To Time]小于[From Time] + [Break],否则[Date1] + 1天。
>
当(显然)T-SQL不支持在一起添加日期和/或时间时,一切都非常困难。
{编辑}抱歉没有说明,但我正在使用SQL Server 2012-R2。
您必须先将日期字段转换为日期时间。
展开 | 选择 | Wr ap | 行号
< blockquote>很奇怪....这对我的环境无效。它是一个版本的东西吗?
这个做了:
展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号
可能是版本的东西。我正在运行SQL Server 2008 R2
I have a system which stores a date value (Date1) and a time value (From Time) in separate fields and I need to work with the full date/time result (FromDT). How can I add these two values together as this seems to be unsupported by T-SQL?
I also have other time fields ([To Time] & [Break]) which allow me to determine the end date/time (EndDT) by using [Date1] unless [To Time] is less than [From Time] + [Break], in which case [Date1] + 1 day.
All very difficult when (apparently) T-SQL doesn''t support adding of dates and/or times together.
{Edit}Apologies for not stating earlier, but I''m using SQL Server 2012-R2.解决方案You have to convert the date field to datetime first.
Expand|Select|Wrap|Line Numbers
Weird....that did not work on my environment. Is it a version thing?
This one did:
Expand|Select|Wrap|Line Numbers
Could be a version thing. I''m running SQL Server 2008 R2
这篇关于如何在T-SQL中添加两个日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆