I get a date/time as double value from C# (DateTime.ToOADate(), which is a OLE Date Time). It contains the passed days from 1899/12/31, with the fraction being the passed part of the day. Multiplied with 86400 I get the seconds and from that finally the day's time.
Getting the date however is harder. I still don't have an solution except for the dates that the UNIX time covers (1970/01/01 to 2038/01/19). During this time, mktime() can be used to convert the passed days to a datetime.
double OleDateTimeValue = 28170.654351851852; // 14.02.1977 15:42:16
struct tm * timeinfo;
int passedDays = (int)OLEDateTimeValue;
// between 1.1.1970 and 18.1.2038
if((passedDays >= 25569) && (passedDays <= 50423))
{
timeinfo->tm_year = 70; //1970
timeinfo->tm_mon = 0;
timeinfo->tm_mday = 1 + (passedDays - 25569);
mktime(timeinfo);
}
else // date outside the UNIX date/time
{
}
Now, mktime() formats the tm struct so that it represents the requested date, or returns -1 if the value is outside the given dates.
Is there a generic way to do the calculation? Unfortunately I can't use MFC and have to use Visual C++ 6.0.
Thanks, Markus