I am trying to create Dataview Webpart for SharePoint Calendar Events to display [Today] items. I was sucessful on that, my next challenge is how to make it time sensitive. I want to display events only when its time.

For example I have two events [Today]. First Event starts at 9am until 10:15 am and Second appointment starts from 10:30 am until 10:30 pm.

As of this moment i can see both events in view. I there a way to make calendar only display

Event one between 9am to 10:15am and that would expire or disappear from view. display event two when its 10:30am until 10:30 pm.

Any comments or suggestion would be greatly appreciated.

Thank You

1 Answer 1


You can do this with SharePoint Designer. Like any view, you have a little more flexibility when you edit the CAML directly. Unfortunately, the Calendar view format causes the CAML to be fully escaped and makes it less straight forward.

  1. Create a new view using the Calendar View view format. Specify all the options you want. Change the Default scope to Day.
  2. Add a simple filter (we will replace this) such as All Day Event is equal to Yes
  3. Modify the view in SharePoint Designer
  4. Find the ListViewXml element in the WebPart and scroll all the way over to where you see <Query><Where>...
  5. Just past the close of the DateRangesOverlap element </DateRangesOverlap> is where your custom CAML filter can begin. (You'll see whatever filter you specified in step 2)
  6. Select everything between </DateRangesOverlap> and </And></Where></Query>
  7. Replace your selection with the following: <Or><And><Eq><FieldRef Name="fAllDayEvent"/><Value Type="AllDayEvent">1</Value></Eq><Eq><FieldRef Name="EventDate"/><Value Type="DateTime"><Today/></Value></Eq></And><And><Leq><FieldRef Name="EventDate"/><Value Type="DateTime" IncludeTimeValue="True"><Today/></Value></Leq><Geq><FieldRef Name="EndDate"/><Value Type="DateTime" IncludeTimeValue="True"><Today/></Value></Geq></And></Or>

  8. Save your view. Every time you refresh your calendar will only show all day events and events happening right now

The above escaped CAML is easier to understand when written like this:

            <FieldRef Name="fAllDayEvent"/>
            <Value Type="AllDayEvent">1</Value>
            <FieldRef Name="EventDate"/>
            <Value Type="DateTime">
            <FieldRef Name="EventDate"/>
            <Value Type="DateTime" IncludeTimeValue="True">
            <FieldRef Name="EndDate"/>
            <Value Type="DateTime" IncludeTimeValue="True">

Standard Day View: Standard Day View

Same Calendar using New View (Taken at 9:30 am) Same Calendar using New View

  • Just a thought - I don't think this will work with recurring events after the first instance.
    – Ryan
    Commented Aug 28, 2012 at 9:00
  • 1
    @Ryan Recurring events do show up, the problem is they all show up regardless of scheduled time since the start time is the beginning of the first occurrence and the end time is the end of the last occurrence. So the above solution only works as desired when no recurring events are scheduled. This makes this a pretty lousy solution, but without somehow parsing and interpreting the RecurrenceData Field's XML rules, there doesn't appear to be a way to do this using the Calendar View. Commented Aug 28, 2012 at 13:39
  • Hello Chris Thank You for your solution. I cant find ListViewXml in the webpart i am creating. Also just for the information. I am creating DataViewWebppart using Calendar as a list. Where in view i have title and primary contact Info(custom column) and JOb INfo(custom column).Then i Applied filter where All Day Event is equal to Yes . Commented Aug 28, 2012 at 13:55
  • It gave me this <SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" UseServerDataFormat="true" selectcommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;fAllDayEvent&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;1&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" id="dataformwebpart1"><SelectParameters><SharePoint:SPDataSource>. Then i tried replacing your caml query after selectcommand="". It gave me error saying It is not valid. Any thoughts on that. Thank You Commented Aug 28, 2012 at 14:00
  • I also Followed you instructions exactly but got this: WebPartPages:ListViewWebPart-An error has occured. Commented Aug 28, 2012 at 14:19

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.