5

How can I query my custom list and only show items if the field dateField, is in today's month?

Here is my query so far:

<Query>
 <Where>
  <Or>
<Eq>
  <FieldRef Name="dateField"></FieldRef>
  <Value Type="Datetime"> <Month /> </Value>
</Eq>
<IsNotNull>
  <FieldRef Name="dateField"></FieldRef>
</IsNotNull>
 </Or>
</Where>
</Query>
7

Date range would be better:

   <Where>  <And>
     <Geq>
        <FieldRef Name='DateField2BeFiltered' />
        <Value Type='DateTime'>2014-08-01T12:00:00Z</Value>
     </Geq>
     <Lt>
        <FieldRef Name='HmniaEggrafou' />
        <Value Type='DateField2BeFiltered'>2014-09-01T12:00:00Z</Value>
     </Lt>
   </And>  </Where>

There's a great tool named http://www.camldesigner.com that helps a lot

| improve this answer | |
2

have you tried combining CAML with JavaScript?

Get the current month:

JS:

var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var myDate = new Date();
var currentMonth = monthNames[myDate.getMonth()];

CAML:

 <Query>
 <Where>
 <Or>
 <Eq>
 <FieldRef Name="dateField"></FieldRef>
 <Value Type="Datetime"> <Month />+ currentMonth + </Value>
 </Eq>
 <IsNotNull>
 <FieldRef Name="dateField"></FieldRef>
 </IsNotNull>
 </Or>
 </Where>
 </Query>
| improve this answer | |

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.