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>
    <Where>
        <Geq>
            <FieldRef Name="ImageCreateDate" />
            <Value Type="DateTime">
                <Today OffsetDays="-7" />
            </Value>
        </Geq>
    </Where>
</Query>
 
There you go, easy date math in CAML!
Tags:

 

Links to this post

Enterprise Collaboration and Virtual Teams Report (March 7, 2008)

Trackback from Effective Collaboration on 07 Mar 2008 05:07

CKS:EBE Resources

Trackback from thekid.me.uk on 12 Mar 2008 11:58

Comments

On 22 Aug 2008 08:35, Patrick said:

Thanks... DOesn't matter if you don't post that much... Just post cool things like this!

On 23 Nov 2008 08:00, Anil said:

hi any one can tell me how to make the date expiry for 180 days from date of publish

Leave a comment