Hi I am currently writing a sharepoint add in application which reads and writes to sharepoint lists.

For one of the lists I want to retrieve a list item based on the user logged in and also based on a start and end date that the user enters in a html form.

Is there anyway I can do this using CAML Queries?

I am able to retrieve the list items submitted by the user currently logged in using the following query:

    "<View><Query><Where><Eq><FieldRef Name='UserName' LookupId='True'/><Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value></Eq></Where></Query></View>"  

I just don't know how to have the start and end dates as query conditions also.


the start date in the list is named 'DateFrom' the end date is named 'DateTo'

Date variables in the function are as follows:

var dateFrom = document.getElementById("dateFrom").value;
var dateTo =   document.getElementById("dateFrom").value;

Thanks for any help/suggestions.

1 Answer 1


try this: format of DateTime should be 2015-06-05 00:00:00.

I hope I prepared it correctly:

           <FieldRef Name='UserName' LookupId='True'/>
           <Value Type='Lookup'>" + _spPageContextInfo.userId + "</Value>
                <FieldRef Name='DateFrom' />
                <Value Type='DateTime'>" + dateFrom.toString("yyyy-MM-dd HH:mm:ss") + "</Value>
                <FieldRef Name='DateTo' />
                <Value Type='DateTime'>" + dateTo.toString("yyyy-MM-dd HH:mm:ss") + "</Value>
  • Thank you that seemed to work, only thing there was an extra </Eq> tag and also the end </Where> tag was missing. Aside from Thank You! Jan 30, 2019 at 15:07
  • Youre welcome :) you can give me Vote up to! :) Jan 30, 2019 at 15:08
  • I havent selected whole code, now is correct. Jan 30, 2019 at 15:09

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.