I was wondering if there is a way to convert an OLE date and time into a readable format using c++?

I have looked at some of what time.h offers but cant find anything to convert OLE


thanks, i was doing a bit or research and i came across this function. Ive been reading up on it and i think its exactly what ive been looking for. Do you know of any examples how this function can be implimented?

my programming knowledge is basic and im am not sure what this function requires to get it working. all i have is my 8 bytes stored in

unsigned char stamp[8];

i know im asking quite a bit but im completely stuck. can you help me out? its ok if you cant il try to research some more

thanks for the advice

First you have a DATE object, I don't know how you got that DATE but assume it comes from an SQL database query. So I'll just fake it here.

#include <windows.h>
#include <iostream>
using std::out;

int main()
    DATE dt = 123.4457676; // some fake number
    SYSTEMTIME stime;
    OleTimeToSystemTime( dt, &stime ); // convert to structure
    cout << stime.wMonth << "/" << stime.wDay << " " << stime.Year << "\n";

Click the link for SYSTEMTIME and you will see all the other structure members that you can use.

thanks ancient dragon. ive just got a couple more questions then hopefully il be sorted! 1st one is that OleTimeToSystemTime is bringing up an error as an undefinded function. This stumped me a little.

and second, the number for DATE dt in my prgram will be a string of hex stored in an array. will i stille be able to get the time and date from it?

thanks for your help

Q1: That's because I gave you bad info -- should be VariantTimeToSystemTime()

Q2: I don't know what that hex string is. Never saw it like that. Can you post an example?

This is an example of how im storing the time stamp:

in ascii my time stamp is: |þ+ÚNã@

unsigned char _1,_2,_3,_4,_5,_6,_7,_8;

infile.read (&_1,sizeof (_1)) ;		
infile.read (&_2,sizeof (_2)) ;
infile.read (&_3,sizeof (_3)) ;		
infile.read (&_4,sizeof (_4)) ;
infile.read (&_5,sizeof (_5)) ;		
infile.read (&_6,sizeof (_6)) ;
infile.read (&_7,sizeof (_7)) ;		
infile.read (&_8,sizeof (_8)) ;

char time_array[] = {_1,_2,_3,_4,_5,_6,_7,_8,'\0'};  // timestamp stored in array

so i end up with the timestamp stored in my array. But im worried that i will not be able to use it stored in this way? will i be able to input the variable time_array into the varianttimetosystemtime function?

thanks for your patients

It looks like that is the binary representation of a double. So why not just read it directly into a double and not bother with all that other code.

DATE dt;
infile.read(&dt, sizeof(dt));

my time stamp is stored in little endian format which is why i stored each byte into a seperate variable so that i could then reverse the bits? Will the function do all this for me or will i need to feed it the variable in the correct format for it to work. For instance i think it works from a ieee float variable where as my array just stores the eight bytes as they come. Will i need to convert to ieee or will the function just get the correct information?


I don't know the answer to that so you will probably have to experiment to find out exactly how to do it. Another possibility is after you store it in that binary array

DATE dt.
memcpy(&dt, time_array, sizeof(DATE));

this is my final post, ive got my program working now so just wanna say thanks for you help and patients Acient Dragon! nice one:)