Trying to convert timestamps that are given in seconds after Jan first 1970. I have written a small function in Excel VBA to convert to the Excel date format. This works fine in the sense that it converts to a number that if formatted correctly gives the timestamp in an intelligible way, but I have to format the calls by hand each time. I have tried to address the issue in several ways, but either it does not do anything to the number, or it results in an error: "#VALUE." The function is called Sec2TS and if I use: 1502569847 as input it returns: 42959.8547106481, which is correct, but I would like to see: 2017 Aug 12 20:30:47. I have added the code:
Function Sec2TS(Secs As Double) As Date
If Secs > 0 Then
Sec2TS = 25569 + (Secs / 86400)
Else
Sec2TS = 0
End If
ActiveCell.NumberFormat = "yyyy mmm dd hh:mm:ss"
End Function
What is wrong with this? I have tried with set range to selection and toggling application, but to no avail.
