I have a SharePoint 2013 list in which I have a date field say Formatted Date, now using CAML Query I need to retrieve only the records which have year 2017 in the Formatted Date.PFB my code:

    operation: "GetListItems",
    listName:"Test List",
    CAMLViewFields: '<ViewFields><FieldRef Name=\Region\'/><FieldRef Name=\FormattedDate\'/></ViewFields>',     
    CAMLQuery:"<Query><Where><And><Eq><FieldRef Name=\Region\'><Value Type='Choice'>"+region[i]+"</Value><Contains><FieldRef Name=\FormattedDate\'><Value Type='DateTime'>2017</Value></Contains></Eq></And></Where></Query>",
    async: false,
    completefunc: function (xData, Status) 
        year2016= parseInt($(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"));

But the count is retrieved as 0. Can somebody help? Thanks in advance

  • is the internal name correct ? what is the column type of formatted date column ? Jun 13, 2017 at 8:55
  • 1
    Create a calculate field =TEXT([Date],"yyyy") and query the year from that field.
    – Nag1987
    Jun 13, 2017 at 9:30

2 Answers 2


Your ending </Eq> tag is misplaced. It should be placed before the <Contains> tag. Also some of your escapings are incorrect.

               <FieldRef Name='Region'>
               <Value Type='Choice'>"+region[i]+"</Value>
               <FieldRef Name='FormattedDate'>
               <Value Type='DateTime'>2017</Value>

Also, I'm not sure if the <Contains> will work on a date-time field. I normally try to use something like:

Greater than or equal to 2017-01-01 AND Less than 2018-01-01


Below is the correct query, please note use this date format for strLeaveStartDateFilter and strLeaveEndDateFilter string objects

string strLeaveStartDateFilter = "2017-01-01";
string strLeaveEndDateFilter  = "2018-01-01"

                    <FieldRef Name='Region'></FieldRef>
                    <Value Type='Choice'>"+region[i]+"</Value>
                            <FieldRef Name='FormattedDate'></FieldRef>
                                <Value Type='DateTime' IncludeTimeValue='FALSE'>" + strLeaveStartDateFilter + @"</Value>
                            <FieldRef Name='FormattedDate'></FieldRef>
                                <Value Type='DateTime' IncludeTimeValue='FALSE'>" + strLeaveEndDateFilter + @"</Value>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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