Comparing to a time in a CQWP

I had been struggling to find out how to compare a time in a CAML statement for a while now (not that I was looking particularly hard though). To do a date comparison is easy using the <Today/> tag, but I was (and still am!) confused as to why the <Now/> tag doesn’t work in the query, as it’s listed in the SDK. Very frustrating!

However I came across this blog on the Microsoft ECM team blog, where buried in the comments trail there was a little gem!

Normally to compare a date in a Query override you would use something like:

<Geq><FieldRef Name=”Expires” /><Value Type=”DateTime”><Today /></Value></Geq>

this will compare the whole date, so if the items date is today it will be included, no matter what the time. If you want to compare the time also, you need to add this IncludeTimeValue attribute to the Value tag:

<Geq><FieldRef Name=”Expires” /><Value Type=”DateTime” IncludeTimeValue=”TRUE”><Today /></Value></Geq>

Pretty simple, one of those annoying little bits of crucial info that’s really hard to find!


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: