Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Filtering views by Time and Date

with 15 comments

An earlier blog entry describes how to filter List and Document views by date. However, the [Today] function, by default, returns only the date and not the time. Therefore, this solution does not solve mad-tie’s problem of wanting to filter on items created in the last hour.

CAML queries can include time as well as date when using the [Today] function. This is described by this blog by ucsharp. In CAML when using the [Today] function you can use the “IncludeTimeValue” attribute to specify that time as well as date should be used:

<Value Type=”DateTime” IncludeTimeValue=”TRUE”><Today /></Value>

Now, the problem is that you cannot include this attribute through the SharePoint user interface, but it can be done with SharePoint Designer. So, to create a view that displays items created in the last hour:

  • Create a calculated column called “DatePlusHour” of “Date and Time” type using the “Date & Time” format in the list or document library (as done by mad-tie):


This takes the date/time of when the item was created and adds one hour (1/24 = 0.4166…).

  • Modify the view (e.g. “All Items”) to filter based on [Today]:


Now the CAML query so created needs to be manually edited to include the IncludeTimeValue attribute:

  • Run Microsoft Designer and open the site in which the list or document library resides.
  • Locate the list or document library and open the .aspx file associated with the view (e.g. “AllItems.aspx”.
  • Click the Code tab and locate the CAML query associated with the filter (search on “DatePlusHour”).
  • Edit the CAML query to include the IncludeTimeValue attribute. NOTE: Include spaces exactly as show!

    &lt;FieldRef Name=&quot;DatePlusHour&quot;/&gt;
    &lt;Value Type=&quot;DateTime&quot; IncludeTimeValue=&quot;True&quot;&gt;

It should look like the following:


WARNING: If the SharePoint user interface is used to modify the view the IncludeTimeValue attribute will need to be readded using the instructions above.


Written by Nick Grattan

April 24, 2008 at 1:59 pm

15 Responses

Subscribe to comments with RSS.

  1. Nick,
    I’m having problems with getting this to work. This my first time dealing with CAML. I didn’t add the additional hour to my column but I don’t see how that should affect it. I actually have two fields to filter on; a Begins fiels and Expires field.

    Here is my code. Please let me know what I’m doing wrong. Thanks.

    Where><And><Leq><FieldRef Name=”Begins”/><Value Type=”DateTime”>IncludeTimeValue="True"><Today/></Value></Leq><Geq><FieldRef Name=”Expires”/><Value Type=”DateTime”>IncludeTimeValue="True"><Today/></Value></Geq></And><


    June 26, 2008 at 9:45 pm

  2. Nevermind Nick, I figured it out! Thanks for posting this; it was a huge help!


    June 26, 2008 at 10:03 pm

  3. […] once I knew what to look for I found some other blogs and forums mentioning this issue. It turns out the UCSharp blog had already blogged […]

  4. Good idea, but when you reach the element limit and use paging, it doesn’t work anymore.


    August 21, 2008 at 10:27 am

  5. i have added IncludeTimeValue as advised and THIS DOES NOT WORK FOR ME, i am traying to filter by date time and only the date is used. Is there any explanation for that.Help Urgently needed
    <FieldRef Name="Escalate_x0020_Time"/>
    <Value Type="DateTime" IncludeTimeValue="True">


    March 23, 2009 at 6:46 am

  6. it is now working the problem was the space between

    Type=”DateTime” and IncludeTimeValue=”True


    March 23, 2009 at 7:55 am

  7. Hello,
    What do you mean by ” the problem was the space between”? Today function seems not working for me 😦


    August 31, 2009 at 2:00 pm

  8. </OrderBy

    after doing this also Im getting error while loading web part


    May 18, 2010 at 12:57 pm

  9. Excellent tip, thank you!

    Jussi Palo

    January 16, 2012 at 9:09 am

  10. The problem with all of these blogs is that every solution starts with “Use SharePoint Designer to…” Many of us do not have access to SharePoint Designer and are limited to the user interface, so I find that 99% of the answers on these forums are useless to me. Just an observatoin – goes for all SharePoint forums, not just this one.

    John Blaser

    April 19, 2013 at 5:12 pm

  11. IncludeTimeValue=”True” giving time of 12:00 am not the current time
    anyone can please help?

    Vinesh Nagpal

    April 3, 2015 at 7:42 am

  12. Hi,
    Unfortunately, I do not have access to SharePoint Designer for my site due to security policy. Is there another way around filtering views by date and time?



    December 8, 2017 at 12:39 am

    • Hi Nick,

      Sorry, but I don’t know off-hand on how to do this without SharePoint designer,

      Regards, Nick.

      Nick Grattan

      December 8, 2017 at 12:58 pm

  13. I to am an employee on a locked down SOE environment without access to Sharepoint designer. I am just wondering, have you or anyone reading this tried using a script editor web part to run some java to filter an all items list by time? i.e. hide list items that do not match criteria? for example I have an roster of people on call column A = date/time of start of their shift and column b = date/time end of shift. OOTB I can display all people where start [today] it shows everyone who’s shift start or ends “today” but does not narrow down to the person specifically roster right NOW, that requires start date AND time NOW (date+time). We all know [today] doesn’t cut it, and some of us do not have ability to edit CAML, So maybe we can filter Allitem.aspx using Java?


    March 19, 2018 at 11:22 am

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: