Search code examples
datetimeodatadataexplorer

Now() or Today() in OData


I have created the StackOverflow OData query Find unanswered questions by non-noob.

It works fine so far, except that I want to limit the questions to questions asked in the last N days (e.g. 7 days).

I have tried

datetime'##Since##T00:00:00'

and I have read posts like OData Date query, but none of them is specifying the date in a relative way to today.

How can I complete my query to select new questions only?


Solution

  • I found the solution for your problem over here so I added the following lines:

    DECLARE @today Datetime = getdate()
    DECLARE @NrDays int = ##NrDays:int?7##
    

    ...

    and datediff(Day,CreationDate,@today) <= @NrDays
    

    So this is my solution: Find unanswered questions by non-noob within last week