Page 1 of 1

How to convert datetime to double VC++ in order

Posted: Fri Feb 20, 2004 3:32 pm
by 9080443
to use it in CalcXPosValue(somedouble_from_datetime)?

I saw the way to do it in Delphi by 'EncodeDate()' function, but how about VC++?
Any ideas would be gretly appreciated. Thanks.

Igor.

Posted: Mon Feb 23, 2004 9:26 am
by Pep
Hi,

in VC++, TeeChart uses a COleDateTime object to define datetime, e.g.

COleDateTime datevalue;
datevalue = COleDateTime(doublevalue);

Posted: Mon Feb 23, 2004 3:57 pm
by 9080443
Hi,
Thank you for reply. But actually I need a reverse operation to be done - get a double from COleDateTime. I have my bottom axes as of date type. And I need to know a real coordinates those correspond to certain dates on bottom axes. To achive this I guess I need to use function CalcXPos(double). So I need that certain date on bottom axes to be coverted in double in order to use it in CalcXPos function. Any ideas?

Thanks.

Posted: Tue Feb 24, 2004 11:17 am
by Pep
Hi,

how about using DOUBLE(x):

DoubleValue = DOUBLE(COleDateTimeValue);

?

Posted: Sat Feb 28, 2004 9:23 pm
by 9080443
Hi,
Actually I did not find that macro DOUBLE(x) in VC++ documentation, but on the other hand it gace me an idea and below is how I solved my conversion problem via ChangeType function:

Code: Select all

COleVariant oleDateVar;
		oleDateVar.ChangeType(VT_DATE);
		COleDateTime oleDate(nYear, nMonth, nDay, 12, 0, 0);
		oleDateVar = oleDate;
		
		oleDateVar.ChangeType(VT_R8);
		nDoubleDateValue = V_R8(&oleDateVar);
long nX = cBottomAxis.CalcXPosValue(nDoubleDateValue/100.0);
However it seems converted it not exactly to the double which was used by chart when building Bottom axis datevalue for that date. So I should devide it by 100 to get some approximate coordinate to what is really needed. But still it's not the exact value. Have you an idea how to get exact value which exactly corresponds to the coordinate on bottom axis?

Thank you again for your time.

Posted: Mon Mar 01, 2004 12:17 am
by 9080443
Hi,
An issue is off for now, I have found what was the problem. Anyway thank you for your help.

Igor.