0

I'm trying to subtract an hour from this date - 2016-08-25 1:19:30.560. I expect and want to get 2016-08-25 12:19:30.560.

Instead I get: 2016-08-25 00:19:30.560

If I then set the date to 2016-08-25 2:19:30.560. I then get 2016-08-25 01:19:30.560. It does it properly.

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
2
  • 6
    Do you mean 1 PM? 1 PM is 13:00 in SQL. Commented Aug 25, 2016 at 20:03
  • @AdamV . . . You should write and answer and explain the logic. Commented Aug 25, 2016 at 20:05

1 Answer 1

3

1:19:30.560 is 1:19 AM in SQL. If you want PM, you need 13:19:30.560 instead, or else you'll need to provide a "PM" like so:

SET @FakeCurrentDateTime1 = '2016-08-25 1:19:30.560 PM' 
Sign up to request clarification or add additional context in comments.

1 Comment

Or express the time as 13:19:30.560.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.