0

I am currently using

SELECT FORMAT (getdate(), 'MM/dd/yyyy, hh:mm:ss tt') as date

The output is in the format I need, but is off by 6 hours.

05/30/2019, 06:26:01 PM

I just need to add 6 hours to it. been using dateadd, but I keep loosing the format I need it to be on.

SELECT DATEADD(Hours,6,GETDATE()) outputs in wrong format

3
  • So, why don't you combine the two?: SELECT FORMAT(DATEADD(Hours,6,GETDATE()), 'MM/dd/yyyy, hh:mm:ss tt') AS date ; Commented May 30, 2019 at 16:35
  • Or change the server to the desired timezone... Commented May 30, 2019 at 17:03
  • Thanks, I figured that is what I needed to do. just cant do it right, thanks
    – lviz
    Commented May 31, 2019 at 9:51

2 Answers 2

0

You need to call the DATEADD function inside the FORMAT function:

SELECT FORMAT( DATEADD(HOUR, 6, GETDATE()), 'MM/dd/yyyy, hh:mm:ss tt') as date
0
Declare @dt datetime ;
select @dt=  DATEADD(Hour,6,GETDATE())
SELECT FORMAT (@dt, 'MM/dd/yyyy, hh:mm:ss tt') as date

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.