Query Work Items changed in recent hours

Yesterday I got another question on one of our internal mailing list and I remembered it as one that I’ve answered before on OzTFS.com. The answer comes from this MSDN forum post.

By default, the TFS Work Item Query engine operates in “date precision” mode. This means that you can only run queries like:

  • Show me all the work items changed in the last week
  • Show me all the work items changed in the last day

If you want to query on work items changed within a narrower timeframe, you’ll need to call the object model directly and turn off “date precision” mode. For example:

  • Show me all the work items that have changed since 5AM today.

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace WorkItemQueryByHour
    class Program
        static void Main(string[] args)
            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://your-tfsserver:8080", new UICredentialsProvider());
            WorkItemStore wis = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

            Query query = new Query(wis, "SELECT [System.Id], [System.Title], [System.ChangedDate] FROM WorkItems WHERE [System.ChangedDate] > '2008-10-01 05:00:00'", null, false);

            ICancelableAsyncResult car = query.BeginQuery();
            WorkItemCollection items = query.EndQuery(car);


Comments (1)
  1. Shai Raiten on Power Tools 2008 – TFSUsers/TFSManager and How To: Add Custom Build Steps to TeamBuild…

Comments are closed.

Skip to main content