Thursday, January 29, 2009

Today in CAML query

I had to use [Today] in a CAML query. I tried configuring the query with the U2U Caml Query Builder 2007, this was the output:

<Where>
      <Eq>
         <FieldRef Name='Modified' />
         <Value Type='DateTime'>[Today-120Day(s)]</Value>
      </Eq>
</Where>

But this did not work when a tried to run the query in code (SPQuery). I used this query instead, and it worked fine:

<Where>
      <Eq>
         <FieldRef Name='Modified' />
         <Value Type='DateTime'><Today OffsetDays="-120"/></Value>
      </Eq>
</Where> 

3 comments:

Anonymous said...

thnx man, just what i needed.

Larry said...

Thanks! It helped me too!

Anonymous said...

Thanks a lot :) it helped !!!