I am pulling some data using VBA and the range where I need the date and time is like a huge number and it is not able to format as yyyy/mm/dd, it is like that: 1651680385. I tried formula or change the format in Excel but, it doesn't work.
Below is the code which I am still not able to understand where is the issue. I appreciate any advice.
Function theTimeinYard(unixTime As String) As String
Dim tiy As Double
Dim tiyd As Date
Dim days As Double
Dim hours As Double
Dim minutes As Double
Dim hou As Double
tiy = CDbl(unixTime) ' / 60# / 60# / 24#) '- DATE(1970,1,1)
tiyd = ModUtilities.fromUnix(tiy)
days = 0
minutes = 0
hours = 0
If ((DateDiff("n", tiyd, Now) / 60) >= 24) Then
days = DateDiff("d", tiyd, Now) 'how many days
tiyd = DateAdd("d", days, tiyd) 'recalculate date
End If
If (days < 4) Then ' 4 or more days just mention days
'how many minutes
minutes = DateDiff("n", tiyd, Now)
hou = (minutos / 60) ' calcs
hours = Int(hou)
minutes = Int((hou - Int(hou)) * 60)
End If
theTimeinYard = IIf(days > 0#, days & " days", "") & IIf(hours > 0#, " " & hours & " hours", "") & IIf(minutes > 0, " " & minutes & " min", "")
End Function
Please, try the next simple function:
It returns a
Datein the standard format. Like anyDateyou may change the format as you want.I am not its 'father', I found it on the net with some year before...
You can test it using the next sub and your UNIX number (from the question):