Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何选择第一列日期和第二列时间作为日期时间_Sql_Date_Time - Fatal编程技术网

Sql 如何选择第一列日期和第二列时间作为日期时间

Sql 如何选择第一列日期和第二列时间作为日期时间,sql,date,time,Sql,Date,Time,我想选择第一个字段的日期部分和时间部分减去第二个字段的3小时作为datetime。我已经尝试了以下方法,它只需要几个小时的时间场,因为我只需要几个小时。如何通过将完成日期和时间减去3小时来实现。如果有简单的方法,请帮助我 declare @ReminderDate DATETIME='2013-12-22 01:01:01.000' declare @ReminderTime DATETIME='2014-09-10 14:09:00.000' select cast(cast(cast(

我想选择第一个字段的日期部分和时间部分减去第二个字段的3小时作为datetime。我已经尝试了以下方法,它只需要几个小时的时间场,因为我只需要几个小时。如何通过将完成日期和时间减去3小时来实现。如果有简单的方法,请帮助我

declare @ReminderDate DATETIME='2013-12-22 01:01:01.000' 
declare @ReminderTime DATETIME='2014-09-10 14:09:00.000'

select cast(cast(cast( @ContactMadeReminderDate as DATE) as nvarchar(15))+' ' + cast(LEFT(CONVERT(TIME(0), @ContactMadeReminderTime), 2)-3  as nvarchar(15) ) +':00' as datetime)
请尝试此查询

SELECT CAST(CAST(@ReminderDate AS Date) AS DateTime) + CAST(DATEADD(HOUR,-3,@ReminderTime) AS TIME)