Is there a way in an Excel VBA macro to get the current datetime in UTC format?
I can call Now()
to get the current time in the local timezone; is there a generic way to then convert this to UTC?
Simply, you can use COM Object to achieve UTC Time Information.
Dim dt As Object, utc As Date
Set dt = CreateObject("WbemScripting.SWbemDateTime")
dt.SetVarDate Now
utc = dt.GetVarDate(False)
http://excel.tips.net/Pages/T002185_Automatically_Converting_to_GMT.html
There is a macro on that page with a LocalTimeToUTC method. Looks like it would do the trick. Also some formula examples if you wanted to go that route.
Edit - Another link. http://www.cpearson.com/excel/TimeZoneAndDaylightTime.aspx This page has several methods for date/time. Pick your poison. Either should do the trick, but I feel like the second is prettier. ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With