I am trying to get a function to convert Unix time to Excel date time. I need to be able to enter =UnixToDTM(A1) to get the Excel date/time value of the Unix date that is stored in cell A1.
I have the formula that works but I do not want to enter it every time I need to do this conversion. The working formula is:
=(((A1/60)/60)/24)+DATE(1970,1,1)+(-5/24)
the -5/24 adjusts for timezone.
I tried this code but all I get is a #name? error:
Public Function UnixToDTM(ByVal sUNIX As Long) As Double
Dim sValue As Double
sValue = (sUNIX / 86400) + 25569 + (-5 / 24)
UnixToDTM = sValue
End Function
I have never done a function before and am stuck on this one. Any help is appreciated.
Bookmarks