How are DateTime and Number formats encoded in Jet4?

徘徊边缘 提交于 2019-12-02 09:45:18

If I have the raw 8 byte value for Datetime fields, how can I convert this to a string representation of the date such as "MM-DD-YY HH:MM:SS"?

Access stores Date/Time values as 64 bit (8 byte) Double values in little-endian format. The integer portion represents the number of days before or after the Access "epoch" (1899-12-30 00:00:00) and the absolute value of the fractional portion represents the time portion for that day (e.g., 0.5 = Noon). So, for example, in Python we would convert the bytes into a datetime value like so:

from datetime import datetime, timedelta
import struct

# bytes as retrieved from .accdb or .mdb file
d_as_bytes = b'\x35\x07\x2F\x2C\x93\x63\xDD\xC0'

d_as_double = struct.unpack('<d', d_as_bytes)[0]  # -30094.29957175926
d_integer_part = int(d_as_double)  # -30094
d_fractional_part = abs(d_as_double - d_integer_part)  # 0.29957175926
access_epoch = datetime(1899, 12, 30)
d = access_epoch + timedelta(days=d_integer_part) + timedelta(days=d_fractional_part)
print(d)  # 1817-08-08 07:11:23

No. The JET format is proprietary of Microsoft and not documented.

As for the Date data type, this is simply a double.

Neither double nor single carry a format. As you mention, these a standard floating point values.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!