Search code examples
apitfstfs-2015

TFS API get TestResults in a specific date range


How can I get test results completed in a specific date range using the TFS API? I used queries like

SELECT * FROM TestResult WHERE completedDate BETWEEN '2016-09-03' AND '2017-05-19'

or

SELECT * FROM TestResult WHERE completedDate > '1.5.2017'

But both resulted in a "Bad request" response of the TFS API.

Is there something wrong in the syntax querying a date field?

Querys for other fields work well, e.g.

Select * From TestResult Where TestCaseId = 25406

Solution

  • The correct format is:

    var testresults = teamProject.TestResults.Query("SELECT * FROM TestResult WHERE DateCompleted < '2017-05-24 07:41:44.137'");
    

    The Field is DateCompleted and the time format is 2017-05-24 00:00:00.000.

    Note:

    The DateCompleted stored in database is using UTC time, so when you run the query you should convert your local time to UTC time to get more accurate results