# The <today/> tag not working in my CAML Query?

I am trying to retrieve the 5 most upcoming (with respect to expiry date) announcement list item "Title's".The query partly works but what it fails to do is include and display todays announcements as well (For ex: Announcements posted earlier in the morning).

I looked around the net and all of that suggests adding the IncludeTimeValue='TRUE' in the tag, but it still does not work. What am I missing? I have also tried using the <now/>.

• This looks like it should work to me. I know this sounds like a stupid question, are you certain the data is there to supply the expected results? – Robert Kaucher Mar 23 '12 at 15:58

Unless you're sure that all the announcements you want has an Expire datetime then you're missing an "or+isnull" like this:

<Query>
<Where>
<And>
<IsNotNull>
<FieldRef Name="Title" />
</IsNotNull>
<Or>
<IsNull>
<FieldRef Name="Expires" />
</IsNull>
<Geq>
<FieldRef Name="Expires" />
<Value IncludeTimeValue="TRUE" Type="DateTime">
<Today />
</Value>
</Geq>
</Or>
</And>
</Where>
<OrderBy>
<FieldRef Name="Expires" Ascending="True" />
</OrderBy>
</Query>


• I tried adding the <or> content, but it would still not display todays announcements. I have put up a screenshot for reference. I tried the <Now/> tag as well and it wouldnt work. Please advise. – user7400 Mar 23 '12 at 18:17
• Interesting observation. I tried the same query to retrieve calendar (event list) items and it displays just fine with the <today/> function. However it still does not display items that have expired an hour ago, which is good. – user7400 Mar 23 '12 at 19:16

I just used the date and not the datetime. Since it was just announcements I didn't mind it being on the page for an extra day. The default expires field only holds the data value anyway. A simple <geq> on the Expires field with type="Date" did it for me.

I set up some announcements exactly like what you have in the screen shot. I did not get correct results in my view until I, for some reason, included the Expires field in the ViewFields element.

<View Name="{5613B6A8-3D6D-40B0-9597-8CDBD9DD92AC}" Type="HTML" DisplayName="TodayOrLater" Url="/teams/root/it/Lists/Announcements/TodayOrLater.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/announce.png">
<Query>
<Where>
<And>
<IsNotNull>
<FieldRef Name="Title"/>
</IsNotNull>
<Geq>
<FieldRef Name="Expires"/>
<Value Type="DateTime">
<Today/>
</Value>
</Geq>
</And>
</Where>
</Query>
<ViewFields>
<FieldRef Name="Attachments"/>