Epoch and Date Time Conversion in Visual Basic for Applications (VBA)

Visual Basic for Applications (VBA) is an implementation of Visual Basic 6 from Microsoft. It provides many date time functions to handle date time functionality.

Here we will explain Visual Basic for Applications (VBA) date time functions to get current epoch or Unix timestamp, convert timestamp to date and convert date to epoch or Unix timestamp.


Get current epoch or Unix timestamp in Visual Basic for Applications (VBA)

You can get the current unix timestamp using DateDiff() function like below.

DateDiff("s", "1/1/1970 00:00:00", Now())

Convert epoch or Unix timestamp to date in Visual Basic for Applications (VBA)

You can get the date from unix timestamp using DateAdd() function like below.

DateAdd("s", 1625383193, "1/1/1970 00:00:00")

Convert date to epoch or unix timestamp in Visual Basic for Applications (VBA)

You can convert the date to unix timestamp using DateDiff() function like below.

DateDiff("s", "1/1/1970 00:00:00", "2021-07-04")



More about date time in Basic for Applications (VBA)