steamboy naratsu
steamboy naratsu

Reputation: 17

VBA macro converting time to PST

Dim dt As Object, utc As Date
Set dt = CreateObject("WbemScripting.SWbemDateTime")
dt.SetVarDate Now
utc = dt.GetVarDate(False)

Hello! I just saw this code somewhere in this page, but this code converts the time to UTC.

But can someone help me to convert it to PST instead?

Thank you!

Upvotes: 0

Views: 616

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

Consider:

Sub TimeOnMyHands()
    Dim dt As Object, utc As Date, pst As Date
    Set dt = CreateObject("WbemScripting.SWbemDateTime")
    
    dt.SetVarDate Now
    utc = dt.GetVarDate(False)
    pst = utc - TimeSerial(8, 0, 0)

    MsgBox utc & vbCrLf & pst
End Sub

enter image description here

Upvotes: 3

Related Questions