How to get the current datetime in UTC from an Excel VBA macro

Viewed 75856

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?

7 Answers

Sigh. The question is about Excel VBA, NOT about "Excel VBA for Windows". In short, none of the answers, however upvoted they may be, works on a Mac or on Linux (yes, Office, at least Office 2000, runs on Linux too)

So here is my answer. It's predictible it gets zero vote, but truth is not a beauty contest.

For Windows, see the other answers (those that silently assume Windows, demonstrating how programmers create problems by assuming things).

For the Mac, see https://macscripter.net/viewtopic.php?id=41117.

For Linux, see How do I get GMT time in Unix?

Have fun with VBA. Sorry to be so dry, but there's so much approximation going arround, S.O. gets scary now.

Related