ADO: Getting Milliseconds
Hi ...
I am trying to get Milliseconds from a SQL Database using ADO. The code below will return 0 for the wMilliseconds.
Any comments / solutions.
Thanks,
Chris
Code:
// Some code is removed for clarity
_variant_t vTemp;
COleDateTime codtUpdateDateTime;
// Define ADO connection pointers
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRecordset = NULL;
try
{
// When we open the application we will open the ADO connection
pConnection.CreateInstance(__uuidof(Connection));
// Open the ado connection
pConnection->Open(bstrConnect,"","",adConnectUnspecified);
// Select all the records
csSQL = "SELECT * FROM dbo.MacgowanTest00";
// Create an instance of the database
pRecordset.CreateInstance(__uuidof(Recordset));
// This is required to support the Sort Property
pRecordset->CursorLocation = adUseClient;
// Open the recordset
pRecordset->Open(LPCTSTR(csSQL),
pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
while (pRecordset->GetadoEOF() == VARIANT_FALSE)
{
vTemp = pRecordset->Fields->GetItem(L"UpdateDateTime")->Value;
// Try to get the millisonds here
SYSTEMTIME sTime;
codtUpdateDateTime = vTemp.date;
codtUpdateDateTime.GetAsSystemTime(sTime);
int ms=sTime.wMilliseconds;
}
}
catch(...)
{
// handle error
}
Re: ADO: Getting Milliseconds
Well..., why are you sure the "Milliseconds" must be non-zero?
Re: ADO: Getting Milliseconds
Chris,
This could be a timer resolution problem. I have the same type of code in my computer and it does the same thing. I remember reading somewhere that the timer resolution in XP is about 15ms, so a search taking less than 15ms will show 0ms. If anyone can verify this correct or incorrect please step on my toes, I'd rather have that than incorrect information. Try putting a Sleep(30) in your code before "codtUpdateDateTime.GetAsSystemTime(sTime);" and then ck your time.