The past days I received some questions regarding CAML and the use of dates in it. Being awfully busy myself, I delegated it to our CAML girl :). It costs me a couple of beers, but it is worth it. She promply answered the questions, so let me share one of them with everybody.

Question:

A question, I would like to run a CAML query where a WSS column as datetime has to be compared to the present time.
My CAML knowledge is very poor. I exepected to be able to do this but it doesn't work :

<Where>
<Gt>
<FieldRef Name="EventDate" />
<Value Type="DateTime"><ows:Today/></Value>
</Gt>
</Where>


When I validate this CAML query (as a CAML filter for the BlueDoglimited Syndication Generator), I receive this error message : 'ows' is an undeclared namespace
Can you help ? Would it be possible to introduce something like Today - 5 (days ?)

Answer from our CAML girl:

x will not work. You have to enter CAML dates in the following format: yyyy-mm-ddThh:mm:ss.
 
So, you're query in the CAML Builder should look like the following:

<Where>
<Ge>
<FieldRef Name="EventDate" />
<Value Type="DateTime">2005-5-27T00:00:00Z</Value>
</Ge>
</Where>

I know, this way your date is static and I suppose you want it dynamic. If you build your CAML query dynamically in code, you can use functions like SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today). This will convert your date from a DateTime value into a CAML Date format, which is the ISO8601 format.