Extract Date from MemoryBlock.Int64Value

Hi, I have MemoryBlock (LittleEndian=True) and part of it is a Date as
06 41 49 64 43 1e d7 01 (8 bytes, Int64 I think.)
Which suppose to be Timestamp: Tue 21, 2021 12:14:42.488346200 Hour standard Romance
Im not really sure how to convert it to date and how to convert date to its Int64 Value
Can anyone help me with that?

Thanks and best regards

8 bytes could be a double or int64 value representing a datetime as a number of seconds using the Unix epoch.

If you are using API 2 you could try something like:

myDateTimeVar = New DateTime(myMemoryBlockVar.DoubleValue(0))

or

myDateTimeVar = New DateTime(myMemoryBlockVar.Int64Value(0))

If you are using the Date class then you would need to set TotalSeconds to the value probably with an offset which is the difference between the Unix epoch and the Xojo (Mac) epoch.

1 Like

Hi Keving,
Yes its Unix epoch.
Not really sure why must be 66 years shifted but works.
I have this for convert.
This returns Int64Value from Date:

Public Function unix_date(d As Date) as Int64
Dim UA_DATATIME_USEC As Double = 10.0
Dim UA_DATATIME_MSEC As Double = UA_DATATIME_USEC * 1000.0
Dim UA_DATATIME_SEC As Double = UA_DATATIME_MSEC *1000.0
Dim UA_DATATIME_UNIX_EPOCH As Double = 11644473600 * UA_DATATIME_SEC
Dim Ret As Double
d.Year = d.Year - 66
d.Hour = d.Hour - 1
Ret = (d.TotalSeconds * UA_DATATIME_SEC) + UA_DATATIME_UNIX_EPOCH
Return Ret
End Function

And this one returns date from Int64Value

Public Function unix_date(iUnixDate As Int64) as Date
Dim UA_DATATIME_USEC As Double = 10.0
Dim UA_DATATIME_MSEC As Double = UA_DATATIME_USEC * 1000.0
Dim UA_DATATIME_SEC As Double = UA_DATATIME_MSEC *1000.0
Dim UA_DATATIME_UNIX_EPOCH As Double = 11644473600 * UA_DATATIME_SEC

Dim d As New Date
d.TotalSeconds = (iUnixDate - UA_DATATIME_UNIX_EPOCH) / UA_DATATIME_SEC
d.Year = d.Year + 66
d.Hour = d.Hour + 1

Return d
End Function

Thanks for a hint!
Regards

TotalSeconds uses the macOS Classic Epoch which is Jan 1st 1904 which is 66 years earlier.

All clear now.
Thanks!