VBA to convert system time to different time zone

kris21

New member
Joined
Jul 2, 2016
Messages
24
Reaction score
0
Points
0
Hi Gurus,

How can I convert my system time to a different time zone . Say GMT? I use the below code to get the time of running the macro. I would like to display this time in GMT as the workbook is used by global audience.

Code:
   Sheet1.Range("C1").Value = DateTime.Now


Thanks in advance guys :)
 
Code:
Sub M_snb()
    c00 = "HKLM\system\currentcontrolset\control\timezoneinformation\"
    With CreateObject("wscript.shell")
        MsgBox Now & "   (GMT " & IIf(.regread(c00 & "bias") < 0, "+", "-") & -.regread(c00 & "bias") \ 60 & ")"
    End With
End Sub
 
Don't be afraid of API calls or "long" code. Most don't know how all details about a car but they can drive it.

Chip's routine is extremely easy to use.
=ConvertLocalToGMT(A1, TRUE)

In any time conversion, you do need to know if daylight saving time was/is in effect. For me, it is.

This one works well too.
http://excel.tips.net/T002185_Automatically_Converting_to_GMT.html
 
Last edited:
Some people are afraid to use 'normal' VBA:

Code:
Sub M_snb()
    MsgBox Now, , "Your time"

    MsgBox DateAdd("n", CreateObject("wscript.shell").regread("HKLM\system\currentcontrolset\control\timezoneinformation\bias"), Now), , "GMT time"
End Sub
 
Thank you so much for your time Kenneth and snb :) :) :) :)

Much Appreciated !!
 
Back
Top