CAML Query with dynamic date evaluation

Wow, it’s been over a week since ODC2008 and I haven’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 items 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!

Advertisements
This entry was posted in CAML, SharePoint. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s