In this SharePoint CAML query filter tutorial, we will discuss how we can use CAML based on created date range in SharePoint 2013/2016/Online. How to use caml query between two dates in SharePoint Online/2013.
So I have written the query in the below format where startDate is the created start date and endDate is the created end date. And also I have included IncludeTimeValue=’FALSE’, so that it will not consider the time part in the created date.
query = “<View Scope=’RecursiveAll’><Query><Where><And><Geq><FieldRef Name=’Created’/><Value Type=’DateTime’ IncludeTimeValue=’FALSE’>”+startDate+ “</Value></Geq><Leq><FieldRef Name=’Created’/><Value Type=’DateTime’ IncludeTimeValue=’FALSE’>”+ endDate + “</Value></Leq></And></Where></Query></View>”;
When I run this query, it did not give me the result. After doing some research, I found that I gave the incorrect date format.
I had given the date format as “yyyy-dd-mmT00:00:01Z“. And it was the reason the filter was not working. When I change the format to “yyyy-mm-ddT00:00:01Z” the filter started working. So my startDate and endDate will be like below:
This is a very silly issue, but just want to share because if you ever face this kind of issue you may check the date format. Will surely save your time.
You may like following SharePoint CAML Query examples:
- How to Use CAML Query for Boolean field for SharePoint 2013/2016/Online Object Model CSOM
- Download, Install and Use CAML Query Helper in SharePoint Online/2013/2010/2007
- Caml query builder SharePoint 2013 Online
- CAML Query Builder for SharePoint 2013/2016/Online
- Filter CAML Query by List Item ID in SharePoint Online/2013/2016
- SharePoint CAML Query Order by Example with Dropdown in SharePoint Online/2013/2016
- Task assigned to user or current user groups in SharePoint 2010 using CAML query
Hope this SharePoint 2013 caml query example helps you to filter records between two days in SharePoint Online/2013/2016.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.