.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Client Object Model with Date Query in SharePoint 2010

Posted By:Jean Paul       Posted Date: March 31, 2013    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we will explore the solution for handling date in client object model. I hope the code could help you in a scenario involving client object model. The attachment contains the code we have discussed.

In this article we can explore some of the challenges faced working with the Client Object Model along with Date values.


You are working on a Task list which contains creation date of different months.  You need to search and find the tasks of current month. 
How to achieve this using CAML at Client Object Model?


Following is the data for the Task list:

Note: The test application contains a Create Data button to generate the list & data for you.  Please ensure you are running on a test SharePoint server.

Using the Application

You can download and run the attached source code.

The buttons perform the following:

Create Data:
Creates the Task list with some monthly data

Show All Data:
Shows all the items in Task list in the grid below

Show this Month Data:
Shows only the current month data using CAML query filtering

CAML Query

Following is the CAML query for specifying the dates:
query.ViewXml = @"<View>" +
"<Query>" +
  "<Where>" +
  "<Geq>" +
  "<FieldRef Name='DueDate'/>" +
  "<Value Type='DateTime' IncludeTimeValue='FALSE'>" + startDateFx + "</Value>" +
  "</Geq>" +
  "<Leq>" +
  "<FieldRef Name='DueDate'/>" +
  "<Value Type='DateTime' IncludeTimeValue='FALSE'>" + endDatFx + "</Value>" +
  "</Leq>" +
  "</Where>" +
"</Query>" +


We are using Geq (Greater than or Equal) and Leq (Less than or Equal) filters in the query.

Date Format

Please note that the dates are formatted as below:
string startDateFx = startDate.ToString("yyyy-MM-ddTHH:mm:ssZ");
string endDatFx = endDate.ToString("yyyy-MM-ddTHH:mm:ssZ");

Please note that in the Server Object Model we can use the SPUtility.CreateISO8601DateTimeFromSystemDateTime method to achieve the same. 

CAML Query Builder

You can validate your CAML queries using the following tool:

U2U CAML Query Builder


Executing the Application

On executing the application and clicking the buttons we can see the results below:

The first task list displays all the items and the second task list displays on the items in the current month based on the Due Date column.




In this article we have explored the solution for handling date in client object model.  I hope the code could help you in a scenario involving client object model.  The attachment contains the code we have discussed.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend