datetime storage format in .DAT

Forum Home Forums Uncategorized Issues datetime storage format in .DAT

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2480
    gianguido
    Participant

    Dear all!

    I would like to use RapidSCADA as a “pure” Linux/Ubuntu installation, that is, without need of any Microsoft products or solutions at all, either runtime or for development. For that reason I am currently developing a Python interface to edit the data tables directly. All aspects are so far clear, with the exception of the datetime storage format.

    For example, in ctrlcnl.dat the following timestamps (8 Bytes) can be extracted from different records:

    [174] [143] [156] [225] [157] [213] [228] [64]
    [53] [227] [189] [225] [157] [213] [228] [64]
    [217] [244] [220] [225] [157] [213] [228] [64]

    (all data in decimal representation 0-255)

    My guess so far is that datetime must be in a 8-Byte format, probably with 4 Bytes for time with milliseconds and 4 Bytes for the date. The actual date is probably 21-11-2016 (as of the published examples) or near it and be represented by the sequence [157] [213] [228] [64]. I tried different codings (SQL, Unix, etc.) and algorithms, but I am not able to make sense out of it. Can you please tell the procedure to transform the given Byte sequence in a formatted day/time and back? An overall algorithm to YYYY, MM, DD, HH, MM, SS as integer would be perfect(!), the presentation strings can be easily built from them. Thank you!

    #2484
    Mikhail
    Moderator

    Hello,
    The encoding of date and time is common and platform independent.
    First of all, this is a double value.
    Integer part is a number of days starting from 1899-12-30
    Decimal part is a part of a day:
    0.0 is 0:00:00
    0.5 is 12:00:00
    See this and this descriptions.

    #2486
    gianguido
    Participant

    Thank you, Mikhail!

    on the basis of your suggestions the following procedure with Python works.

    1. read the 8-Byte sequence
    2. use ‘struct.unpack’ to convert the binary string to double-precision float
    3. build a datetime.timedelta object
    4. add to datetime (1899,12,30)
    5. format the output string as wished with strftime()

    the datetime.timedelta function operates on the date and the time concurrently, no need to treat their values separately.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.