Search code examples
sqlvbscriptqtp

UFT doesnt get milliseconds from SQL


Trying to get time from MS SQL. The time format in database is MM/DD/YYY hh:mm:ss.mls. When reading via UFT, it gets the time without milliseconds but rounds seconds by milliseconds, i.e. if it is 1:48:33.724, UFT gives 1:48:34 and if it is 1:48:33.245 UFT gives 1:48:33. How to avoid that rounding and get full time format?


Solution

  • As commented, I had to modify my query to return the milliseconds. I modified to this:

    SELECT p.Name, P.Description,p.Share, e.Name, p.OpenSDate, p.OpenEDate, p.EffectiveDate, p.CreatedBy, CAST(p.CreateDate AS datetime2(3)) AS 'CreateDate', p.DeativedBy, CAST(p.DeactiveDate AS datetime2(3)) AS 'DeactiveDate' FROM [tblProgram] p inner join [tblMapping] pm on p.ProgramID = pm.ProgramID inner join [tblEntity] e on pm.EntityID = e.EntityID order by 1,4
    

    Originally, database had 3 numbers for milliseconds, so I used datetime2(3). In UFT I just splitted it:

    dbDate = CDate(Split(dbCellData, ChrW(32))(0)) 'this gives the date part
    longtime = Split(dbCellData, ChrW(32))(1) 'this gives the time part with milliseconds
    dbtime = Split(longtime, ".")(0) 'this gives time without milliseconds but not rounded
    

    Referral: https://learn.microsoft.com/en-us/sql/t-sql/data-types/datetime2-transact-sql