Feb23
CAML Query with dynamic date evaluation
Categories: CAML, SharePoint
Wow, it's been over a weke since ODC2008 and I havn't posted, how slack of me. It's been a busy week talking about a lot of the cool things that I saw at ODC and cutting a lot of code.
Anyway I noticed that there is almost no documentation around how to do date based queries in CAML, particularly when you want to use a date that is evaluated at runtime.
The CAML query below show how to find iten that have an ImageCreateDate in the last seven days.
<Query>
<Geq>
<FieldRef Name="ImageCreateDate" />
<Value Type="DateTime">
<Today OffsetDays="-7" />
</Value>
</Geq>
</Where>
</Query>
There you go, easy date math in CAML!