CAML Request Comparing DateTime with Eq

I am trying to assemble a CAML request that compares two DateTime objects, but I cannot get it to work using Eq comparison . From my testing, I can get Gt, Lt, Geq, Leq to work with DateTime comparisons, but Eq doesn't work at all at all.

The first object is the Date and Time field (created by InfoPath and stored in the Date and Time field in the SharePoint list), the current example is 3/14/2012 12:00 AM. I tried to use the [Today /] value using a hard-coded value in the ISO 2012-03-14T00: 00: 00Z format, but so far nothing has worked. I experimented with IncludeTimeValue, setting it to true / false, without improvement.

My current query looks something like this:

<Query>
 <Where>
  <Eq>
   <FieldRef Name="SomeDateTimeField" IncludeTimeValue="TRUE" />
   <Value Type="DateTime" IncludeTimeValue="TRUE">2012-03-14T00:00:00Z</Value>
  </Eq>
 </Where>
</Query>

This does not return anything, although I have an element with this date time in the list. Any ideas?

+5
source share
2 answers

An equal statement cannot return anything, since seconds are counted. Try using a date range. Example:

<Where>
 <And>
  <Gt>
   <FieldRef Name='Created' />
   <Value IncludeTimeValue='TRUE' Type='DateTime'>2014-12-10T00:00:00Z</Value>
  </Gt>
  <Lt>
   <FieldRef Name='Created' />
   <Value IncludeTimeValue='TRUE' Type='DateTime'>2014-12-10T23:59:59Z</Value>
  </Lt>
 </And>
</Where>

Please note, we are using the same date but a different time.

+2
source

It works:

<Query><Where><Eq><FieldRef Name="SomeDateTimeField"/><Value IncludeTimeValue='TRUE' Type='DateTime'>2012-03-14T00:00:00</Value></Eq></Where></Query>
+1
source

All Articles