我试图从这个日期减去一小时 - 2016-08-25 1:19:30.560。我期待并希望得到2016-08-25 12:19:30.560。
相反,我得到:2016-08-25 00:19:30.560
如果我将日期设置为2016-08-25 2:19:30.560。然后我得到2016-08-25 01:19:30.560。它做得恰到好处。
DECLARE @FakeCurrentDateTime1 datetime
DECLARE @FakeCurrentDateTime2 datetime
SET @FakeCurrentDateTime1 = '2016-08-25 1:19:30.560'
SET @FakeCurrentDateTime2 = DATEADD(hour, -1, @FakeCurrentDateTime1)
SELECT @FakeCurrentDateTime2
DECLARE @FakeCurrentDateTime3 datetime
DECLARE @FakeCurrentDateTime4 datetime
SET @FakeCurrentDateTime3 = '2016-08-25 2:19:30.560'
SET @FakeCurrentDateTime4 = DATEADD(hour, -1, @FakeCurrentDateTime3)
SELECT @FakeCurrentDateTime4
答案 0 :(得分:3)
1:19:30.560
是在SQL中的1:19 AM。如果你想要PM,你需要13:19:30.560
,否则你需要提供一个" PM"像这样:
SET @FakeCurrentDateTime1 = '2016-08-25 1:19:30.560 PM'