Microsoft KB Archive/185859

= INFO: OLE Servers Return Date Calculation Results as Seconds =

Article ID: 185859

Article Last Modified on 12/11/1999

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a

-



This article was previously published under Q185859



SUMMARY
By default, a date data type passed in to or out of a Visual FoxPro OLE server is automatically converted to Datetime format. Because of this, the result of a date calculation is returned as seconds.



MORE INFORMATION
The Visual FoxPro OLE servers, by default, convert the Date data type to DateTime. If you try to subtract two datetime variables, within an OLE server, the result is returned as seconds (n * 86400). You may use the TTOD function if you need the number returned as days.

Steps to Reproduce Behavior
  Using Visual FoxPro, build an OLE DLL using the following code and name it DateFunc: DEFINE CLASS DateFunc AS custom OLEPUBLIC

Name = "DateFunc"

PROCEDURE DifferDate PARAMETERS BDate, EDate x=EDate-BDate RETURN INT(x) ENDPROC

ENDDEFINE   After building the OLE DLL, issue the following commands in the Command window: ox=CREATEOBJECT("DateFunc.DateFunc") ? ox.Differdate({01/01/98},{01/05/98}) Note that instead of returning four days, 345600 (4*86400) seconds is returned.   To return four days from the OLE DLL, replace the commands in the DifferDate procedure as shown below: PROCEDURE DifferDate PARAMETERS BDate, EDate x=ttod(EDate)-ttod(BDate) RETURN INT(x) ENDPROC 

