Aman Varshney
Aman Varshney

Reputation: 3

Filter workitems created within a time range using Wiql

I want to filter all the workitems, created between a specified DateTime range. I am using TFS2015 (on-premise) to filter this, but always getting the following error InnerException {"You cannot supply a time with the date when running a query using date precision. The error is caused by «[System.CreatedDate] > '1970-01-01 00:00:00.000 GMT'»."} System.Exception {Microsoft.VisualStudio.Services.Common.VssServiceException} even when I used the filter timePrecision: true.

I tried the same code with ADO services (on-cloud) project and TFS2017+ versions and it works fine with that.

My code is

DateTime startTime = new DateTime(1970, 1, 1);
DateTime endTime = DateTime.UtcNow;
const String FORMATTED_DATE_TIME = "yyyy-MM-dd HH:mm:ss.fff 'GMT'";
string FormattedStartTime = startTime.ToString(FORMATTED_DATE_TIME);
string FormattedEndTime = endTime.ToString(FORMATTED_DATE_TIME);
string wiqlQuery = $"SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] ='{projectName}' And  [System.WorkItemType] = '{workItemType}' And [System.CreatedDate] > '{FormattedStartTime}' And [System.CreatedDate] <= '{FormattedEndTime}' ORDER BY [System.CreatedDate] DESC";

Wiql wiql = new Wiql()
{
    Query = wiqlQuery
};

WorkItemQueryResult workItemQueryResult = WitClient.QueryByWiqlAsync(wiql: wiql, project: projectName, timePrecision: true).Result;

Upvotes: 0

Views: 93

Answers (0)

Related Questions