question

Kumar avatar image
Kumar asked

current sql server time and then to add 30 mintues

Hi Guys

I want to get the sql servers current time and then I want to increment the time by 30 mintues. Your assistence will be appreciated. So the query output should be current time + 30 mintues. The format is as below.

YYYY-MM-DD HH:MI:SS(24h)

sqlquery
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sp_lock avatar image
sp_lock answered
select dateadd(n,30, convert(smalldatetime, getdate()))
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

vinay avatar image
vinay answered
SELECT CONVERT(VARCHAR,DATEADD(n,30,GETDATE()),20)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TimothyAWiseman avatar image
TimothyAWiseman answered

Naturally, Jonlee has the best answer of course. But just for the sake of completeness, remember that adding 1 to a date adds 1 day(24 hours). So, if you want to add a half hour, you can add 1/48 to a date. So,

select convert(varchar, getdate() + 1.0/48.0, 120)

Should give you what you want. Of course, Jonlee's answer is probably the way to go in real life, but I for one like having options.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
I have never thought of doing any maths when doing any calculations on getdate(), thanks for the variety. :D
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.