OLE date and time format

This is a discussion on OLE date and time format within the C++ Programming forums, part of the General Programming Boards category; hi this is sort of a follow on post from my previous one involving dates which you guys helped me ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    99

    OLE date and time format

    hi this is sort of a follow on post from my previous one involving dates which you guys helped me with so much.

    I have come across a timestamp stored in OLE format:

    7C FE 2B 04

    that string of hex contains the date 4/4/2008 19:30:44

    does the time.h header allow any ways to convert this?


    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you mean the OLE automation date format as described here?
    If so, I think we're in trouble; interpreting those 4 bytes as an IEEE float gives 1.05e37, which is somewhere in the year 2.87e34. If I try to go backwards, I get that the whole number part should be 39541=0x9a75, and I don't see that anywhere in your number.

    So I think the problem is "what is OLE date format"?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    im not sure what OLE format its in. I have a hex editor that has a handy little funtion that converts it for me. All i know is that when i took that string of the 4 hex bytes and put them into little endian order i got the right time and date.

    Is OLE format going to be a nightmare to convert into a readble format?

    is there no built in c++ functions?

    and finally im not sure that i fully understand how the OLE function works. It stores days from 30/12/1899 is what i think it does?

    thanks

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Further research indicates that this is a double: so eight bytes not four. The whole thing should be 40 E3 4E BA 04 2B FE 7C which is 39541.813009259260 as a decimal which corresponds to 4/4/2008 19:30:44.

    So to interpret, memcopy/reinterpret that eight-byte memory address as a double; the whole number part gives the day, multiply the fractional part to get the hour, multiply the fractional part of *that* multiplication by 60 to give the minutes, etc.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    i dont know how you did it tabstop but the other bytes you came up with are the next ones in my file so whatever you did u where right!!

    curiously though, how did you manage to get 39541.813009259260? reverse the bytes then invert the binary and view in decimal?

    so in theory from then on there should have been 39541.8 days since 30/12/1899? and to get the rest i will have to preform the necessary calculations?



    i am willing to do this however does the header time.h not offer anything that could preform this for me?


    thanks very much for your help!

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    There is a hex/IEEE float converter you can find here. I figured out the 39541.whatever myself (years*365+leap days+days so far this year+etc), typed it in, noticed that it almost matched ('cause I had gotten carried away and did 7:30:30 instead) et voila.

    There's nothing inside the standard time.h. If you're interfacing with OLE using a header, that header might have it. Someone somewhere has already written it, naturally, but it would be an OLE person, not a C person.

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    You can use VariantTimeToSystemTime() to convert an OLE date (double) to a SYSTEMTIME structure.
    http://msdn2.microsoft.com/en-us/library/ms221440.aspx

    gg

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    99
    thank you for your advice! ive had a look at msdn and i think its just a case of implimenting it! haha, so hopefully should have it done in the next year or two! does it work similar to functions used in time.h?

    i have my 8 bytes stored in

    unsigned char time [8];

    but as regards to using the varienttimetosystemtime function im not sure i know to much on how to progress further. I think i need to get my time stored in a double rather then unsigned char to start.

    My programming skills are very basic and i feel that i maybe starting to get out of my depth!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. How to get and set windows time and date
    By huwan in forum Windows Programming
    Replies: 18
    Last Post: 05-13-2008, 10:33 AM
  4. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21