Sharepoint CQWP CAML

using CAML in Content Query WebPart to refine the result is an effective way to customize the result. The use of DateTime is triky.

By Default, To get Today’s Date, you can call

<Value Type=”DateTime”><Today/></Value>

. the date result you get from this caml query doesn’t include the time. to include the time, add IncludeTimeValue=”True” to the Value open Tag.

<Value Type=”DateTime” IncludeTimeValue=”True”><Today/></Value>

The DateTime format used in SharePoint is ISO8601. To convert strand datetime format to the format which sharepoint can understand, call

 SPUtility.CreateISO8601DateTimeFromSystemDateTime(<DateTime>)

You can also retrieve the DateTime offset by days,

<Value Type=”DateTime”><Today OffsetDays=”-10″ /></Value> 

Advertisements

One thought on “Sharepoint CQWP CAML

  1. Old post, I know… but I’m doing a CAML query on a SP doclib. I use the IncludeTimeValue just fine, but there seems to be an offset of sorts. If I give a specific time and I want all documents modified BEFORE that time, I use something like:

    2010-03-01T17:13:00.00-08:00

    but it seems to pick up things modified AFTER the specified time by about 7 or 8 minutes (more than that, they are not picked up…)

    Any ideas on this?

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