CAML Query to get last 6 months items/rows

<Query>
    <Where>
      <And>
        <Geq>
          <FieldRef Name="Date" IncludeTimeValue="FALSE"/>
          <Value Type="DateTime" IncludeTimeValue="FALSE">
            <Today IncludeTimeValue="FALSE" OffsetDays="-180"/>
          </Value>
        </Geq>
        <Leq>
          <FieldRef Name="Date" IncludeTimeValue="FALSE"/>
          <Value Type="DateTime" IncludeTimeValue="FALSE">
            <Today IncludeTimeValue="FALSE"/>
          </Value>
        </Leq>
      </And>
    </Where>
    <OrderBy>
      <FieldRef Name="Date" Ascending="FALSE"/>
    </OrderBy>
  </Query>

I'm using the above CAML Query to get the last 6 months' items which I think, it's not correct because there are different total days each month.

So, how can I get the real items from the last 6 months?

Thanks in advance for any help.

Dear @Ferry_Aritonang,
You can write a custom filtering condition in JavaScript, getting the number of days in the last six months.

Here's how filter can work when replaced from JS - HelpDesk Dashboard

1 Like