I am looking for a way to save a search that includes a relative date. Specifically I am looking for a way to save a search that matches files that have a modification date that is 7 days ago.

I have read the Windows Search Advanced Query Syntax document and I am not seeing a way to say 7 days ago.

The numbers and ranges section does mention that relative dates are possible. The problem is that the relative dates described there do not fit the criteria I need. The lastweek almost looks like what I want except if I run a query like after:lastweek on a Monday it will only show my file that have been modified since Sunday at 12:00. The lastweek/lastmonth seem to relative to the start of the week/month which is not what I need.

Multi-word relative dates: week, next month, last week, past month, or coming year. The values can also be entered contracted, as follows: thisweek, nextmonth, lastweek, pastmonth, comingyear.

One nice thing about saved searches is that they are stored as an XML document and the file format is documented. I am not seeing how to form a correct value for a datetime. If I was able to understand this format, I suspect I could use a text editor and created a saved search that does what I want.

Fragment from the examples:

  <condition type="leafCondition" valuetype="System.StructuredQueryType.DateTime"
             property="System.DateModified" operator="imp" 
             value="R00UUUUUUUUZZXD-30NU" propertyType="wstr" />

To summarize I am looking for an answer to one or both of these questions

  • How do I make a query for '7 days ago' using the standard syntax?
  • How is the DateTime stored in a saved search?

For the first part of your question: R00UUUUUUUUZZXD-30NU tells Windows to search the last 30 days. Changing 30 to 1 (i.e., R00UUUUUUUUZZXD-1NU) would make it search the last 24 hours.

In your case you are looking to set the value to R00UUUUUUUUZZXD-7NU. Reference this forum post.🕗

For the second part of your question perhaps start by looking at the System.DateModified documentation. The other type that's mentioned, System.StructuredQueryType.DateTime, I am unable to find documentation on.


I found this gem🕗 that gets us closer to deciphering how to construct the relative DateTime values. Consider this quote:

For example, Structured Query supports relative date/time expressions, which remain unresolved until they are applied to some reference time. In a leaf node with semantic type System.StructuredQueryType.DateTime, the value can be either a VT_FILETIME or a VT_LPWSTR. VT_FILETIME is an absolute date/time so it is already resolved. VT_LPWSTR is a string representation of a relative date/time expression. The specified reference time should be a local time, but the resolved times in the resulting query expression will be in coordinated universal time (UTC).

and finally this forum posting has another example of what the DateTime is stored.

The best I can tell it is a relative date/time format. I am still unable to find any hard documentation on it.

| improve this answer | |
  • +1. Nice job digging up the meaning of "R00UUUUUUUUZZXD-30NU". – Peter Mortensen Mar 24 '10 at 22:46

Just write a script (PowerShell or Batch) that takes today's date, subtracts 7 days and executes a search based on the result. That way, you won't have to save the search, just run the script.

| improve this answer | |
  • While I agree this is possible work around. This really isn't the solution I am looking for. Plus, somebody should know how the datetime value is structured. – Zoredache Mar 15 '10 at 6:08

I created a sample search file to recreate programmatically. I searched for video files in a specified folder, modified in the last 2 weeks ("datemodified: 3/17/2017..4/1/2017").

This gave me a .search-ms file full of things such as:

<condition type="leafCondition" property="System.DateModified" operator="imp" propertyType="stringarray" value="N00K2017K3K17UUUUUZZNNU; N00K2017K4K1UUUUUZZNNU" valuetype="System.StructuredQueryType.DateTime" localeName="en-US">

The key here being


You can notice the dates are plainly written, prepended by the letter K. N00 then K, then the year, and so on.


I wrote a simple console application to generate a search file with the specific dates of within the last 2 weeks, and set up Windows Task Scheduler to run it every day at midnight for my own purposes. I'm sure you could do the same.

I agree the workaround method is no substitute for being able to generate the search file. One thing people may not know is you can treat .search-ms files as folders, even going as far as to include them as a toolbar folder on your taskbar.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.