epoch (utc) to date

Costas

Administrator
Staff member
<center>
Hj0xlLe.png
</center>

JavaScript:
Private Sub CommandButton1_Click()

    'for the first 2 rows (@ col A there is the epoch value)
    For i = 1 To 2
        Cells(i, 2).Value = AddHour(Epoch2Date(Cells(i, 1).Value))
    Next i

End Sub

'src - http://www.vbforums.com/showthread.php?805245-EPOCH-to-Date-and-vice-versa&p=4934911&viewfull=1#post4934911
Function Epoch2Date(ByVal E As Currency) As Date
Const Estart As Double = #1/1/1970#

  msFrac = 0
  If E > 10000000000@ Then E = E * 0.001: msFrac = E - Int(E)
  Epoch2Date = Estart + (E - msFrac) / 86400
End Function


'src - https://stackoverflow.com/a/31439538/1320686
Function AddHour(ByVal sTime As String) As String
    Dim dt As Date

    dt = CDate(sTime)
    dt = DateAdd("h", 3, dt)

    'ref - https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/format-function-visual-basic-for-applications
    AddHour = Format(dt, "dd/mm/yyyy hh:nn")
End Function

not worked for me - Convert Between Date And Unix Timestamp In Excel
 
Top