How to change a date filter in SharePoint view to include time

So, the question is to filter items in a list by specific date and time – i.e. show up all items modified not earlier than 10:00 AM 8th September 2014 and not later than 10:00 AM 10th September 2014.

To do it, we can make some sort of “injection” to our created view.

In fact, “injected” will be only CAML query of that view.

Using PowerShell:

add-pssnapin microsoft.sharepoint.powershell

$web = get-spweb http://len-shareappt
$list = $web.Lists.TryGetList(‘Заявки’)
$view = $web.GetViewFromUrl(‘http://len-shareappt/Lists/Requests/123456.aspx’)
$view.Query = $query
$view.Update()

And here we will make a change to <Value Type> element – including the phrase IncludeTimeValue=”True”.

Adding it will allow us to add specific time range to a date:

$query = ‘<Where><And><Geq><FieldRef Name=”Modified” /><Value Type=”DateTime” IncludeTimeValue=”True”>2014-09-08T10:00:00Z</Value></Geq><Leq><FieldRef Name=”Modified” /><Value Type=”DateTime” IncludeTimeValue=”True”>2014-09-10T10:00:00Z</Value></Leq></And></Where>’

but this doen’t work for [Today] – so suppose if we need to create a view for all items modified today between 09:00 AM and 10:00 AM this query won’t work:

$query = ‘<Where><And><Geq><FieldRef Name=”Modified” /><Value Type=”DateTime” IncludeTimeValue=”True”><Today />T09:00:00Z</Value></Geq><Leq><FieldRef Name=”Modified” /><Value Type=”DateTime” IncludeTimeValue=”True”><Today />T10:00:00Z</Value></Leq></And></Where>’

Exception setting “Query”: “Name cannot begin with the ‘0’ character, hexadecimal value 0x30. Line 1, position 104.”

How to change a date filter in SharePoint view to include time