SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to filtering dates with REST in SP but am trying to do something like below but am not sure how to get today's date in as a variable into the request. I don't think I'm too far off so any help is greatly appreciated.

    var today = new Date();
        url: "/_api/web/lists/GetByTitle('DateItems')/items?$orderby=SortOrder asc&$filter=StartDate le datetime'" + today + "' and EndDate ge datetime'" + today + "'",
share|improve this question
up vote 15 down vote accepted

Since your "today" variable is a JavaScript date object, you can get the string representation by calling the toISOString() method.

...$filter=StartDate ge datetime'" + today.toISOString() + "' and ...
share|improve this answer
This was the missing piece. Thanks much! – Aaron Jul 2 '14 at 18:40
Unless I'm missing something, this doesn't seem to work in SharePoint 2013 on premises. Or do we need to be at a certain CU or something? I'm about to revert back to SPServices and CAML because I know I can get recurring events, etc. as well as filter by date(s). – Marc D Anderson Jun 19 '15 at 17:35

I answered the question here (not exactly a duplicate, since that was in regards to the Search REST API, and I happened to give an answer for basic REST).

Here is how you filter dates in REST:

$filter=StartDate ge datetime'2014-01-01T00%3a00%3a00'

This filters for items created after 01-Jan-2014, 00:00:00.

So to filter between two date ranges, simply add another condition to the filter:

$filter=(StartDate ge datetime'2014-01-01T00%3a00%3a00') and (EndDate le datetime'2014-04-30T00%3a00%3a00')

This filters for items created between 01-Jan-2014 and 01-May-2014.

Just create your dates in the format: YYYY-MM-DDTHH:MM:SS, and then encode it (or simply use %3a instead of the colons).

share|improve this answer
How can filter just by the Month? – naijacoder Nov 25 '14 at 6:37
@naijacoder How do you mean? You want items where date between March-2014 and July-2014? In that case just use the beginning and end dates of the month (2014-03-01 and 2014-07-31). – wjervis Nov 25 '14 at 11:51

This article explains REST filtering based on date,

You'd want to pass in a date in YYYY-MM-DD format.

share|improve this answer
is there a setting where we can change this to DD-MM-YYYY format? – vignesh Feb 1 at 10:28
No, it uses the ISO date format, you must construct a date string in that fashion – Eric Alexander Feb 1 at 11:53
Thanks Eric. I tried SomeDate>= 27-12-2015 in Dev environment, it worked, but in higher environments SomeDate>=27-12-2015 did not work. Can you please check out the question that I have added for this – vignesh Feb 1 at 12:20

I was pulling the data for online Share-point 2013/ office 365. I used the above method. But It did not return the desired result. I had created the two sample record on with date "2 april 2016". When i use the above syntax, It always return me only one record. I had spent two days to get this work. I made the following addition in above filter.

$filter= (Start_Date ge datetime'2016-04-02T07:00:00.000Z') and (End__Date le datetime'2016-04-03T03:30:00.000Z')

You have to add .000Z to the end of your data-time string to convert the timezone. In the pattern, the inclusion of a 'z' date-time component indicates that timezone format needs to conform to the General time zone "standard", examples of which are Pacific Standard Time; PST; GMT-08:00.A 'Z' indicates that the timezone conforms to the RFC 822 time zone standard, e.g

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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