SharePoint list view filter by hours
The [Today] parameter is a dynamic parameter that can be add some enormous benefit in creating a custom view. Using {Today] is powerful because it can filter a column based on the current date. Show Some examples of ways to use the [Today] parameter are:
Steps to Create a [Today] filtered view:
One limitation of the [Today] field is that it cannot be used for formulas in Calculated Columns. Related Posts:How to Create a Dynamic [Me] Filtered View in SharePoint SharePoint Resources Please leave a comment if you found this post useful.
There are a huge number of articles out there discussing how to create (semi-) dynamic list views or filters based on some volatile property like current time. For instance: “Show me all documents that were created today” or “Show me all documents that were created more than 7 days ago” or “Show me all in tasks due in the next three days”. The solution to this is some combination of a list view filter, or calculated column, and the use of a property like [Today]. (Note: There are a couple of key caveats to do with this.) A limitation of this, however, is that the time portion of a datetime is ignored. So when I wanted to “show all documents created in the last 10 minutes” - I couldn’t. There were a few workarounds - various combinations of calculated columns, using SharePoint Designer and so on were available - but I was determined to find a solution that didn’t require any of this! Alas, I failed. I tried lots of things - Content Query web part, Data View Web Part, calculated columns, custom CAML - but whilst some of it worked, there was either always way too much plumbing required to get it in and it wasn’t particularly deployable between our Dev, Test and Prod environments. The “least pain” and most deployable solution I arrived at is as follows. This describes what I did to achieve my specific requirements - you will need to adjust the parameters and logic to suit your needs. So I wanted a list view that showed all documents in a library that were created more than 10 minutes ago.
[Created] + 0.007 Call your column something memorable - e.g., CalculatedPlus10. You can verify this is doing what you want by adding it to a view and comparing its value against your reference field.
Note that the ” are escaped. This compares the value of your calculated column, and finds items that are Less Than now, including the time portion. Then update the View and as if by magic, your view will now only show items that were created more than 10 minutes ago. Your completed Powershell script might look a bit like this:
I previously shared how to create a “Today” column in SharePoint that would always be up-to-date even if list items weren’t modified. These were no-code solutions that utilized either SharePoint Designer or Microsoft Flow. You can, however, use Today’s date/time to create views and calculated columns without workflow or script or the need to create another column. “Today” in list and library viewsIn views, you’ll need to set filters using [Today]You could also create more complicated filters such as:
Calculated columns with today and/or current timeIn calculated columns, you’ll need to use Today()or Now()as the value for today’s date or today’s date and time.
The difference is Now() uses date and time, so you’ll get down-to-the-minute values (i.e. hours since reported). Today is just date best used for data with no times involved (i.e. days since hire date). The following is a side-by-side comparison using the same “Created” date subtracted from Today() and Now(). You’ll notice the value using Now() is a little higher because it includes the hours already passed today whereas Today() hasn’t changed since midnight. Note: Views using “Today” will always show correctly. The calculated column methods above, however, are a snapshot of today or the current time. They will not update automatically or regularly; just when a list item is modified. If you need a “live” always-updated value regardless of items being modified, you’ll need to create a separate “Today” column using Microsoft Flow or SharePoint Designer: This post also includes ideas for calculations using today’s date. |