2

I have to filter data with respect to a field named CreatedDate having type datetime.

In input I'm just giving date (not time), I want to fetch all records with respect to specific date (ignoring time), I want to use CAML query to do this. How should I ignore time and search by just giving date as input.

Currently, I'm using this CAML query to search:

<Where><Eq><FieldRef Name='Created'/>
  <Value IncludeTimeValue='FALSE' Type='DateTime'>" + createdDate + "</Value></Eq></Where>
1
  • 1
    OMG, it worked perfectly :)) Commented May 18, 2016 at 6:43

2 Answers 2

4

Try this : ---> createdDate.ToString("s")

2
  • No problem. Come again:)) Commented May 18, 2016 at 6:51
  • This works for me :) Commented May 9, 2017 at 12:27
3

Please note that date you are passing in CAML query need to be in ISO8601DateTime format.

string createdDate = startDate.ToString("yyyy-MM-ddTHH:mm:ssZ");

then pass this in CAML query.

Reference: http://www.codeproject.com/Articles/414414/SharePoint-Working-with-Dates-in-CAML

3
  • actually i dont want to give time as i said in my question "i have to ignore time in my input". Commented May 18, 2016 at 6:45
  • However; Goshy's answer worked for me : createdDate.ToString("s") Commented May 18, 2016 at 6:45
  • 3
    Yeah. You can use above code even without passing time. You need to just pass formatted string in CAML query. Both answers are right. :) Commented May 18, 2016 at 6:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.