This article explains how to format Date and Time fields in a NetAnalysis® report.
Formatting Date and Time Fields
In this tutorial, we will create a new report and format the output for a Date/Time field.
When creating or editing reports, use a small number of records to make it easier to preview the results.
Creating a New Report
- Load a workspace into NetAnalysis® and filter the records to reduce the number, if required.
- Create a New Report by selecting Reports » User Defined Reports » New Report from the menu.
- A Report Designer Window will open, as shown below:
The Field List is docked to the top, right-hand side (outlined in red on the image above).
4. Select a Date and Time field from the Field List and drag it onto the Detail section on the report.
Date and Time Formatting
When a field is added to a report, it is possible to change a number of properties relating to that field. The common properties can be accessed by clicking on the smart tag (outlined in red below).
Field properties can also be changed by selecting the item and accessing the properties from the docked panel on the bottom, right-hand side of the Report Designer.
When the smart tag is clicked, you will see the Label Tasks window. One of the options is Format String. The text value for this property will control how the date time value is displayed in the report.
As you can see, the default value shown is:
A Standard date and time format string uses a single format specifier to define the text representation of a date and time value. Any date and time format string that contains more than one character, including white space, is interpreted as a custom date and time format string; for more information, see Custom date and time format strings.
In the example above, the zero represents a place holder for the date time value, and the lowercase "d" character represents the Standard date and time format string for the Short date pattern, as set in options for Microsoft Windows date pattern formats.
5. Click on the Format String's property ellipsis buttonand launch the Format String Editor.
The Format String Editor has a collection of Standard Types and Custom Types. Make sure, DateTime is selected for the Category. You can select from any of the options listed, or add your own.
How to use the General Settings Date Format
As you will be aware, there is an option in NetAnalysis® to set a date format string; this can be found by selecting Tools » Options » General Settings.
You can use this format in your report so that the Date and Time formatting can be changed by the User when working with NetAnalysis®.
To do this, we will make use of the Parameter Fields found underneath the Field List in the Report Designer. There are a number of parameters available for use in your report. See the list in the image below.
The parameter we are going to use is DateTimeFormatString, and we will set that by using the Expression Editor, which can also be accessed from the Field's smart tag.
When you first open the Label Tasks window (after clicking the smart tag), the Expression property will contain the name of the field surrounded by square brackets. As we also use square brackets in our Date field names, the closing square bracket has a backslash escape character immediately before it.
- Click on the Expression's property ellipsis button and launch the Expression Editor:
To configure the formatting, use the following expression:
This will build a formatting string using the DateTimeFormatString parameter and will use the Date Visited [UTC] field. Remember to use the field name exactly as it was shown in the Expression Editor.
The Expression Editor should look like this:
If you are using the Expression method, remember the Format String property should be empty (as shown below):
Each Date and Time field will need to be updated on your report so the formatting method is the same.
All that is left is to save and preview the report to see if it works has expected.