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!

Advertisements

Search Results performance

I was trying some fixed query searches today in order to find all documents recently updated across the MOSS farm. So I set up a Core Search Results web part to find all documents throughout all site collections, and view by modified date and return, say, the 10 most recently modified documents.

I got a bit of a shock when I switched between ‘search by relevance’ and ‘search by modified date’ preferences in the query. By Relevance the search took a reasonable ~0.3sec, however by Modified date took a somewhat more sluggish ~7secs, that quite a difference in my books! Not sure why, but I’ll avoid that one in future!