How to filter a view based on the current date [Today]

If you ever need to filter a view based on calculation from Today’s date, it is pretty simple in SharePoint 2010. All you need is SharePoint Designer.

 

  1. Create a view through the SharePoint UI and set the filter to use [Today] as the filter value.
  2. Open the view in SharePoint Designer
  3. View the source code of the view. You will see the CAML used to create the view right within the source. You should see something like this:
    <Where><Leq><FieldRef/><Value><Today/></Value></Leq></Where>
  4. You can then calculate the number of days from the current date by using the OffsetDays property. The following example will filter the view to show all items within the next 30 days:
    <Where><Leq><FieldRef/><Value><Today OffsetDays=”30”/></Value></Leq></Where>
  5. Save the page and check out your new view.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.