Tuesday, November 27, 2007

SharePoint CAML - filtering on DateTime WITH TimeValue. Finally a solution...

After searching the Internet for quite long now, I've finally managed to locate a solution to executing SPQuery in SharePoint (CAML), by filtering on the TimeValue in DateTime columns.

There have not been any (good) documentation on CAML Queries or SPQuery in the SharePoint SDK.

My temporary solution was to retrieve a larger collection based on the Date-value in DateTime, and then filter on Time-value manually. The code was quite ugly and time-consuming....

Well, as mentioned, there is now a solution to the problem:

The key is to include the following property/parameter in the DateTime tag in the CAML query: IncludeTimeValue="True"

<Value Type=”DateTime” IncludeTimeValue=”TRUE”><Today /></Value>
Creds goes to ucsharp, for posting this in his blog

1 comment:

jt said...

Works perfectly for a data view web part we use.

Thanks for sharing your find!

Business Card