Skip to content
Advertisement

Remove minutes and seconds and then convert to UTC timezone

I have column with time stamp data like this

2021-12-09 08:01:00.520

I want to remove the minutes and second and then convert the date to UTC timezone in one line.

I tried this code

I get this result

2021-12-09 08:00:00.000

and I tried this code

I get this result

2021-12-09 16:01:00.520

What I expected is

2021-12-09 16:00:00.000

How to combine the select statement into one line in simple way

Advertisement

Answer

Here is another way.

To remove the minute, seconds and only keep the hour, you may use the following query

To convert to the UTCDate, just find the different in hour () between GETDATE() and GETUTCDATE() (Since you are not interested in the minute and seconds anyway) and add that to the above query

Putting all together

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement