当ADODB中的小时数> 24时,AVG()时间的结果错误

时间:2019-03-11 10:14:15

标签: excel vba adodb average-precision

有人可以帮助我理解为什么,当我运行此代码时,每次在Kpi1-2> 24H记录的数据范围内,我都会得到错误的结果(示例表是25K recod的提取)。 / p>

enter image description here

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

DBPath = ThisWorkbook.FullName
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
        "Extended Properties=""Excel 8.0;HDR=Yes;"";"    

Strsql:Select [DataAttesa] as Data, avg([Kpi1-2]) as nr FROM [db_In$] Where TypeTrasp  = 'STD' and [1-2_ESITO] in ('90%','100%','Out of Time','On Going') group by [DataAttesa] Order by [DataAttesa]asc

    objRecordset.Open strsql, objConnection, adOpenStatic, adLockReadOnly, adCmdUnspecified
       Do Until objRecordset.EOF
         debug.print objRecordset.Fields.item("nr")
         objRecordset.MoveNext
      Loop
    objRecordset.Close

更新: 我测试这段代码:

debug.print objRecordset.Fields.item("nr")
in the immediate windows I see: 21/01/1900  11:41:00
if I test tu put the result into a cell:

Cells(20, 7) = objRecordset.Fields.item("nr") 
the cells.value will be 22/01/1900  11:41:25
Cells(21, 7) = Format(objRecordset.Fields.item("nr"), "dd/mm/yyyy hh:mm;@")
the cells.value will be 21/01/1900  11:41:25

只有第二个是正确的。 为什么?!?!附加什么?!?

1 个答案:

答案 0 :(得分:0)

此问题的解决方案已在本文中讨论: Difference time view from Excel to VBA

我插入链接是否可以帮助其他用户

fabrizio