5

I need to get the list item created on a particular date. The below caml query doesn't seem to work. It always retuns 0

 query.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='Created'/><Value Type='DateTime' IncludeTimeValue='false'>"+ date +"</Value></Eq></Where></Query></view>";

is there anything wrong in the query?

  • provide the 'date' return type used in query – Dikesh Gandhi Apr 18 '16 at 11:24
  • Hi @DikeshGandhi the date is 4/18/2016 12:00:00 AM – Obiliraj Apr 18 '16 at 11:27
  • I added the answer with SPUtility.CreateISO8601DateTimeFromSystemDateTime . If you need more info, please past your code. – Juan Pablo Pussacq Laborde Apr 18 '16 at 12:12
12

You need to format the date like this:

Server Site

string date = SPUtility.CreateISO8601DateTimeFromSystemDateTime(inputDate);

Sample for your case:

inputDate = new DateTime(2016,04,18);
string date =  SPUtility.CreateISO8601DateTimeFromSystemDateTime(inputDate);

Client Side (client object model)

string date = inputDate.ToString("yyyy-MM-ddTHH:mm:ssZ");
  • Thanks @jpussacq . I'm not sure if this will work on CSOM. but the below worked query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Created' /><Value Type='DateTime' IncludeTimeValue='FALSE' >"+date.ToString("yyyy-MM-ddTHH:mm:ssZ")+"</Value></Eq></Where></Query></view>"; Looks like the sputility method too does the same – Obiliraj Apr 18 '16 at 13:22
  • Yes sorry. I had not realized it was CSOM – Juan Pablo Pussacq Laborde Apr 18 '16 at 13:28
  • Updated my answer! – Juan Pablo Pussacq Laborde Apr 18 '16 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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