0

So I'm trying to create a query using KQL where one of the parameters brings back items that fall under a certain date range - only items that got modified within the past 7 days. Here it is below:

query.QueryText = "(AssignedTo:'" + name + "' ContentType:'Task' StatusOWSCHCS:'Completed' LastModifiedTime>=\"this week\")

The objective is to bring back all tasks assigned to this specific person that were completed within the past week. The rest of the parameters are good to go, but the last doesn't work as intended.

The this week is built in and while it works, it only considers the start of the week (so probably Monday or Sunday) not the week (7 days) before that task was last modified. I feel like there needs to be some sort of calculation to get this done, but something not hardcoded with actual dates (since it would widely vary between different tasks). What can I do to do this? Thank you in advance.

  • Sorry I assumed you are using the query in the Result source or Query settings in the webpart properties. {Today-7} will work only in those scenarios. If you are doing it programmatically then you need to compute the date (-7 days) and pass it to the query like LastModifiedTime>=2015-04-04 – Rajesh Sitaraman Apr 11 '16 at 17:03
  • I'm doing it programmatically and the date cannot be hard-coded since this query will be dependent on today's date instead of one particular date for many different tasks. I was thinking if it's possible to use DateTime.Today and somehow subtract 7 from it to get the current week-ago-date. – LaLaLottie Apr 11 '16 at 19:01
  • I ended up using DateTime.Today.AddDays(-7). Thank you though! – LaLaLottie Apr 11 '16 at 19:11
  • That's what I proposed to compute -7 days from current date and 2015-04-04 was just a final outcome of query. – Rajesh Sitaraman Apr 11 '16 at 19:13
1

Try

query.QueryText = "(AssignedTo:'" + name + "' ContentType:'Task' StatusOWSCHCS:'Completed' LastModifiedTime>='" + $(Get-Date).AddDays(-7) + "'"
1

How about using {Today-7} in your query?

  • How do I structure it exactly? I keep getting a syntax error. – LaLaLottie Apr 11 '16 at 16:15
  • Sorry about I didn't realized now I have liberty to comment on any post. – Rajesh Sitaraman Apr 11 '16 at 16:32

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.