Want to get rid of Google Ads, click here.
+ Reply to Thread
Results 1 to 8 of 8

Thread: Datetime binary format

  1. #1
    Junior Member
    Join Date
    Jul 2002
    Location
    United Kingdom
    Posts
    17

    Default Datetime binary format

    I am trying to read some data from a SQL-mapped SC database. A datetime field is embedded in a binary database field, apparently as 8 bytes. E.g 14 Jan 2004 14:58:23 is stored as [65,207,105,179,209,49,17,17] (decimal).

    Can anyone help with translating this data into a date/time?

    Thanks
    Martin Frain
    Topspeed Consultants Ltd

  2. #2
    Administrator tommy's Avatar
    Join Date
    Nov 2001
    Location
    Copenhagen
    Posts
    4,272

    Default

    This is a wild guess. Perhaps if You calculate a value from the 8 bytes it will be number of seconds (or if it is a really big number milliseconds) past 1/1 1970 ?
    Best regards Tommy
    Blog - - ITIL certified - Accredited Integration Specialist – HP OpenView Service Management

    Want to keep this site alive? Consider making a donation. Click here.

  3. #3
    Junior Member
    Join Date
    Jul 2002
    Location
    United Kingdom
    Posts
    17

    Default

    Hi Tommy

    Tried this first, but the 8 bytes make an integer which is very large - would be something like 300000 years.

    Wondered if there was a special format, such as first 2 bytes = year, next 2 bytes = month etc, but would like to know what the sequence is, whether byte order is reversed.

    Might get it by trial and error, but hope someone could help first.
    Martin Frain
    Topspeed Consultants Ltd

  4. #4
    Senior Member
    Join Date
    Feb 2003
    Posts
    114

    Default

    It's number of seconds since some epoch or other (I want to say January 1, 0000).

    One thing that might be getting you in trouble is that I believe the binary file format prepends a 4 bit type to any size data (the rc string is *not* byte alinged so any given byte may well contain data for more than one datum).

    Thus, a binary unload of a date should be (if memory recalls):

    4 bit type which should be 0011 (binary 3) followed by 64 bits of data (all servicecenter numbers are doubles).

    So total datum size ought to be 68 bits, but many file operations can't write things that don't byte align properly, so in many cases a trailing 4 bits of garbage will be post-pended.

    Note also that if you're unloading a *record* what contains a date, what you're actually unloading is:

    Datum: structure (4 bits 1001)
    Datum: date (4 bits 0011)
    Datum: the date (64 bits data dependent)

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    114

    Default

    The way I had to figure out the file format, back in the day, was just to keep unloading very simple data that are different by only one bit.

    Thus unload 12/25/2003 00:00:00 and 12/25/2003 00:00:01 and see how they differ.

    Then internally translate 12/25/2003 00:00:00 into a number (63240768000), unload *it* and compare the unload of the number with the unload of the date to see how the type-bits work.

  6. #6
    Junior Member
    Join Date
    Jul 2002
    Location
    United Kingdom
    Posts
    17

    Default

    Patrick

    Thanks for the reply. I had an idea this might be fun! The date is contained in a SQL image field which I have read into a byte array. I can decode the strings, but the date appears to be stored as decimal 61 (indicates datetime type?) followed by decimal 8 (length of field?) followed by the 8 bytes of data. I initially tried converting the 8 bytes to a int64, but following your reply I will try using a double.
    Martin Frain
    Topspeed Consultants Ltd

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    114

    Default

    Can you just put the binary bit-stream out here so I can take a look? It's been so many years since I've played with the binary file format that I could be remembering things wrong, but a leading 61 doesn't sound right to me.

    By decimal 61 you mean 00111101? (Hexi 3D)? If so you might be looking at:

    Type 3 (first 4 bits), followed by leading 4 bits of data block. Since dates are always the same binary size, I don't think the RC format includes a size datum e.g. it isn't 4 bits type n bits size x bits data but rather 4 bits type x bits data.

    By the way, today's date is the number: 63243137112
    Binary representation: 111010111001100101011011000001011000
    Hexi:EB995B058

  8. #8
    Junior Member
    Join Date
    Jan 2007
    Posts
    1

    Default

    We noticed that the stop field in the clocks table was mapped to SQL as varbinary. We wanted to use this field for reporting, so we pulled the table back into P4, modified the mapping changing the field to datetime (make sure you set SQL RC to false), and pushed it back out as datetime. ServiceCenter had no problem with this.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts