Working with Dates in Ultimate Forms
It is easy to get tripped up with dates in SharePoint. Dates are troublesome with any software. There are considerations and exceptions when handling leap years, varying number of days in each month and time zone differences. Date headaches are a given, but there are some approaches that will make life easier.
Add your own auto-updating "Current Date" field to a list
Invariably, you need a way to reference the current date in your SharePoint tools.
SharePoint doesn't provide the reference of "Today's Date" in calculated fields.
Using Infowise, you can do it yourself:
- Create a "Date and Time" field named "Current Date".
- Set the format as "Date Only".
- Set the default value as "Today's date".
- Create an Infowise Action with these settings:
- General Settings:
- Name: "Update Current Date"
- Run on events: "Timer-Based", Daily, Hour 12 AM.
- Advanced Settings: (Default)
- Action Settings:
- Values to set: "Current Date" = [Today]
- Items: ID = [ID]
- ID always not equals 0. (Timer actions require at least one condition.)
- General Settings:
Now your list can always reference the current date which will automatically change to the current date each day at midnight. You dashboards will be dynamic and your users will see that KPI Indicator Field automatically change to a Red Flag when the project is late.
Use calculated fields first
Whenever trying to do anything with dates, use calculated fields first. Think of calculated fields as variables that you can add to your list. You won't show these in your forms or list views. These are workers calculating date references for other user facing fields such as progress bars or KPI Flags on your dashboards.
If you haven't practiced with date calculations before, start practicing now! Try creating lots of practice calculations to get a better understanding. Think of this as SharePoint Dates 101. This is must have fundamental learning to have success working with dates. Try to work through these Date and time formulas examples:
Break it into pieces
Calculated fields can reference other calculated fields. Rather than try to build a nasty piece of nested code that handles a long and complicated date calculation, break up the work into multiple calculated fields. Try writing your calculated field formulas in a text editor so that you can check your code carefully. Simply copy and paste your formulas to SharePoint.
Using Infowise Date Functions
Here's a handy list of all the functions available for date calculations in Infowise:
- Year number from a date: $Year()
- Month number from a date: $Month()
- Day number from a date: $Day()
- Day number of the week from a date: $Weekday()
- Week number in the year from a date: $WeekNumber()
- Hour number from a date: $Hour()
- Minute number from a date: $Minute()
- Date Time value of today's date at midnight: $Today()
- Add value to date (Choose Years, Months, Days, Hour, Minutes or Seconds): $AddDate()
- Convert a date related string to a date value (to assign to a date field): $ToDate()
- Get the difference in days between dates: $Days()
- Get the difference in hours between dates: $Hours()
- Get the difference in minutes between dates: $Minutes()
- Get the difference in seconds between dates: $Seconds()
Create a Reference List
Here's a novel approach. Add a list to your site to create date references for handy reference in your other SharePoint lists. You can do all the hard work in this list and create your own "date functions" that SharePoint does not provide! Here is a way to get First date of the current month, Last date of the current month, first date of the previous month and last date of the previous month.
- Create a simple SharePoint custom list and add one field "RefDate" to store date values. (Format set to Date Only.)
- Create four records titled "FirstDateThisMonth", "LastDateThisMonth", "FirstDateLastMonth" and "LastDateLastMonth".
- Now we can add some Infowise Actions to automatically update these values:
- For each action, create a Timer-based action that executes once a month on the first day of each month.
- Set the RefDate value for each action:
- First Date of this month: $ToDate($Month([Today])-1-$Year([Today]))
- Last Date of this month: $ToDate(($Month([Today])+1)-1-$Year([Today]))-1
- First Date of last month: $ToDate(($Month([Today])-1)-1-$Year([Today]))
- Last Date of last month: $ToDate($Month([Today])-1-$Year([Today]))-1
Here is the pay off! Now that we can treat these references as functions in other lists.
For example, if you want to run a monthly report, you can make a reference from an action like this:
This function assumes that the Date-Reference list is in the current site. It selects the record by title and pulls back the date. You can use these references from all over SharePoint to consistently pull back these date values any time it is needed!
With the combined power of Calculated Fields and Infowise Functions there is no limit to what you can calculated for your Date Time fields. Setting up a Date Reference List allows you to create your own Date Time Functions allowing you to do the hard work only once and reference these values from throughout your SharePoint environment.
Do you have a cool approach that you have figured out? Do you have a nasty problem that you can't solve? Post a message and let us know!
Add your comment
100% No-Code Solution
It's never been easier, to create, innovate and share, all you need is your web browser!
Address business process pain points immediately. Save time and money.
Fantastic Support Team
Facing difficulties installing the application? Contact our fantastic support team.