blog.scoreman.net

CAML query with “Today” that includes time value

I was trying to create a CAML query that would filter out all pages with a valid publishing date (and time) using the CrossListQueryInfo object. When I used the <Today/> element in the query it ignored the time.

I remembered reading some were that you could use <Now/> instead of <Today/> but that didn’t do it.

<Leq>
   <FieldRef Name="PublishingStartDate" Nullable="True" Type="DateTime"/>
   <Value Type="DateTime"><Now/></Value>
</Leq>

It turns out that you should use the <Today/> element but that you also need to add a IncludeTimeValue=TRUE attribute.

<Leq>
   <FieldRef Name="PublishingStartDate" Nullable="True" Type="DateTime"/>
   <Value Type="DateTime" IncludeTimeValue="TRUE"><Today/></Value>
</Leq>

Tags: , ,

Leave a Reply