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
FaneDuru's single line is OK for your purpose.
If you prefer extended code, it should add some extra. This function, for example, handles milliseconds as well:
As it is taken from the larger library of mine, VBA.Date , it takes advantage of some supporting functions: