79760720

Date: 2025-09-10 10:12:30
Score: 1
Natty:
Report link

To find the time shift from UTC on a running computer, the code below is the shortest solution I have found:

Function UTCTime()
'Get the UTC
'function from: https://stackoverflow.com/questions/1600875/how-to-get-the-current-datetime-in-utc-from-an-excel-vba-macro
Dim dt As Object, utc As Date
Set dt = CreateObject("WbemScripting.SWbemDateTime")
dt.SetVarDate Now
utc = dt.GetVarDate(False)
UTCTime = utc
End Function

'function to calculate time shift from UTC
Function TimeZone()
TimeZone = Hour(Now() - UTCTime())
End Function
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Łukasz Małarzewski