GETUTCDATE() VS UDF_ConvertLocalToUtcByTimezoneId

Jul 28, 2015 at 4:45 PM
Edited Jul 28, 2015 at 4:46 PM
Hi there,

First, thanks so much for providing this, very useful !

Now, I was wondering if there would be any benefits of using UDF_ConvertLocalToUtcByTimezoneId(getdate(), 'timezone_of_current_server') rather than GETUTCDATE()?

We are in the process of migrating our database to Amazon RDS which does only support UTC timezone at this time and we are currently updating our code base to support this type of conversion.

Thanks and keep up the great work !

Patrice
Coordinator
Jul 28, 2015 at 7:49 PM
Hi Patrice,

for your sample, it would not make any difference at all.

If you want to convert the current local time of your server to the current UTC time, I would even recommend to use the native T-SQL function GETUTCDATE(), because it’s native and higher in performance.

But, of course, UDF_ConvertLocalToUtcByTimezoneId is much more powerful for further use cases:
You can use it to convert any DATETIME value from the past or the future to UTC (e.g. DATETIME values which are stored in any timezone with the records in your database).

Hope, this answers your question?!

Best regards,
Andreas.
Jul 28, 2015 at 8:49 PM
Excellent, thanks Andreas and thank you for putting this together, this is awesome !