I'm working with a DVWP using SPD2010. I need to create a custom data view parameter which will allow me to filter to show the past two days. If I was doing this using within a List View, I'd set the filter to show the items when the column is greater than [Today]-2. How do I put this into the data view parameters in the DVWP filter? When I open the data view parameters dialog, I'm not even sure how to make it work. So, two questions really:

  1. What should I use to set up a simple time based filter?
  2. Is there a good resource available which shows how to build custom filters?


1 Answer 1


This is easier to do with the CAML query than with the DVWP parameters.

Select the DVWP in SharePoint Designer. Let's say the date to filter by is called "TheDate". In the ribbon, click the Filter command and create a filter for TheDate - greater than or equal to - [Current Date].

On the View ribbon, click the Task Panes drop-down and enable the Tag Properties Task pane, which will display on the right.

Go into Code View and find the SharePoint:SPDataSource tag. Click inside this tag.

The Properties Task pane now shows the properties for the tag. Look for the property called SelectCommand. Its contents looks something like

<View><Query><Where><Geq><FieldRef Name="TheDate"/><Value Type="DateTime"><Today/></Value></Geq></Where></Query></View>

You need to edit the <Today/> to include an offset of -2 days: <Today OffsetDays="-2"/> The complete query is:

<View><Query><Where><Geq><FieldRef Name="TheDate"/><Value Type="DateTime"><Today OffsetDays="-2"/></Value></Geq></Where></Query></View>

You may want to copy the contents to Notepad for easier editing, then paste it back into the properties field.

After that, the DVWP shows the desired values.

You can also edit the value right in the code view, but it's a bit unruly, since the brackets are replaced by the lt and gt html codes. It looks like this (after the change)

selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Geq&gt;&lt;FieldRef Name=&quot;TheDate&quot;/&gt;&lt;Value Type=&quot;DateTime&quot;&gt;&lt;Today OffsetDays=&quot;-2&quot;/&gt;&lt;/Value&gt;&lt;/Geq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;"
  • Sweetness. This should also assist me to make other query filters as well. MS sure doesnt make things easy :-) Sep 13, 2013 at 11:37
  • Reporting back: This worked perfectly. It also gives me a means by which I can manipulate this in the future for other needs. Very appreciative ... I'd give you another +1 if I could ;) Sep 16, 2013 at 13:04
  • 1
    Thanks for the feedback. I just changed the title to make it better suited to the question and the answer.
    – teylyn
    Sep 16, 2013 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.