Using Date and Time Fields

From ServiceNow Wiki
Home > Administer > Core Configuration > Time > Using Date and Time Fields
Jump to: navigation, search
Time
Related Topics
Knowledge.gif Get the Book

1 Overview

Records can store date and time values in several different types of fields. These values are stored in the database as integer numbers of milliseconds, and are displayed in the appropriate date or time format.

2 Date and Time Field Types

The following field types are provided for storing date and time information in records.

Field Type Dictionary XML Type MySQL DB Type
Date glide_date DATE
Date-Time glide_date_time DATETIME
Time glide_time DATETIME
Duration glide_duration DATETIME
Due-Date due_date DATETIME


For the full list of field types, see Introduction to Fields.

3 Formatting Date and Time Fields

When modifying the default date and time formats, also verify the format using a Validate Date and Time script.

3.1 Date Format

The date format is defined by the property glide.sys.date_format. An administrator can modify the property by navigating to System Properties > System. Use the same 'format' strings as the java.text.SimpleDateFormat class, with minor exceptions. Note that MM is months, where mm indicates minutes. The format string consists of the following abbreviations.

Field Full Form Short Form
Year yyyy (4 digits) yy (2 digits), y (2 or 4 digits)
Month MMM (name or abbr.) MM (2 digits), M (1 or 2 digits)
Day of Month dd (2 digits) d (1 or 2 digits)

The default format is: yyyy-MM-dd.

3.2 Time Format

The time format is defined by the property glide.sys.time_format. An administrator can modify the property by navigating to System Properties > System. Use the same 'format' strings as the java.text.SimpleDateFormat class, with minor exceptions. The format string consists of the following abbreviations.

Field Full Form Short Form
Hour (1-12) hh (2 digits) h (1 or 2 digits)
Hour (0-23) HH (2 digits) H (1 or 2 digits)
Minute mm (2 digits) m (1 or 2 digits)
Second ss (2 digits) s (1 or 2 digits)

The default format is: HH:mm:ss.

3.3 User Preferences

Users can personalize the format in which date and time values appear in the instance. Personalizing the date or time format does not change global settings or impact the way other users see date values.

  1. Navigate to Self-Service > My Profile.
  2. Select options for the Date format and Time format fields.
    Note: An administrator must add the Time format field to the Self-Service view of the User form. For more information, see Configuring Forms.
  3. Click Update.

4 Configuring the Date Picker for the List Editor

In UI15, a system property enables you to choose between two date picker configurations for the list editor (starting with the Fuji Patch 5 release)

  1. Navigate to sys_properties.list.
  2. Search for the property named glide.ui.list_edit.show_calendar_only.
  3. Set the property Value to either of the following options.
    • false: The date picker displays a calendar as well as a field for manual date entry. This is the default behavior in UI11, regardless of the property value.
    • true: The date picker displays a calendar only. This is the default behavior in UI15.

5 Default Date and Time Fields

Certain time fields are provided by default to store particular date and time fields.

5.1 Global Timestamp Fields

All records inherit the following time stamp fields from the Global [global] table:

  • Created
  • Updated

These fields are automatically populated with the correct date and time.

5.2 Task Fields for Measuring Work Time

The following base system fields are provided on certain tables for keeping track of how long it takes to close tickets:

  • Time worked: A timer which runs while the record is being viewed by a user, and pauses while the record is closed (or when it is paused manually). Used to keep track of the time spent by the help desk while working on the record.
  • Resolve time: A calculated field which measures the time from the moment the record is opened, to the moment the record is closed. Used to keep track of how long it takes to resolve the record.

These fields provide different metrics for request response.

The following additional tools are available for tracking work time:

  • Service level agreements (SLAs): measure how long it takes a record fulfill certain conditions (such as an incident being marked Resolved).
  • Time cards: use the Time worked field to break down how much time was spent by day of the week.

5.2.1 Time Worked

Time-timeworked.png

The Task [task] table provides a time-tracking field called Time worked. This field measures how long a record has been viewed in order to measure work time on a ticket. Any table that extends Task can use this field. To add the field, simply personalize the form.

As the record is viewed, the timer counts upward. To pause the timer, click the stop icon (Timer stop.gifx.gif); to resume the timer, click the start icon (Timer start.gifx.gif).

When the task is saved, the amount of new time in the timer is used to generate a record on the Time Worked [task_time_worked] table. This table can be viewed as a related list on the task form.

By default, the time displayed in the Time worked field displays a cumulative value stored in the task record. If you modify a Time Worked record, the changes will not be reflected in the task timer.

You can set the property com.snc.time_worked.update_task_timer to enable updating of the task timer value based on changes to the time worked records. This is accomplished through the Update task timer business rule.

5.2.2 Resolve Time

The Resolve time field is available on the Incident [incident] and Request [sc_request] tables. The field is calculated by business rules when the record is marked closed, and measures the difference between the Opened by and Closed by dates. This field allows for easy reporting on how long it takes for requests to be closed.

The field is stored in the system as an integer number of seconds.

5.2.2.1 Displaying Resolve Time as a Duration

To display the resolve time as a human-readable duration rather than an integer number of seconds:

  1. Right-click the field on the form.
  2. Select Configure Dictionary (Personalize Dictionary in versions prior to Fuji).
  3. Enter format=glide_duration in the Attributes field. If attributes are already there, add the new attribute separated by a comma and no space.
  4. Click Submit.
    The resolve time will now display in a number of days, hours, and minutes.
Note
Note: This change affects only the display on forms and lists. It does not change the display for reports. Consider reporting duration rather than resolve time to see hours and minutes in a report.


5.2.2.2 Business Rule Calculation

On the Incident table, the field is calculated on closure by the business rule mark_closed. The following lines of code calculate the resolve time:

  current.calendar_stc = 
    gs.dateDiff(
       current.opened_at.getDisplayValue(),
       current.closed_at.getDisplayValue(),
       true);

On the Request table, the field is calculated on closure by the business rule Mark Request Closed. The following line of code calculates the resolve time:

  current.calendar_stc = gs.dateDiff(current.opened_at.getDisplayValue(),current.closed_at.getDisplayValue(),true);

5.3 Planned Task Time Fields

The Planned Task Plugin provides a table (Planned Task [planned task]) with standard fields for measuring a planned task's time. For more information, see Planned Task.

6 Exporting Date and Time Information

Because some export formats are intended for human consumption and others are intended for database usage, different methods provide date and time field information in different formats.

6.1 Excel

Date, Date-Time, and Time fields are all exported as their display values, displayed using a custom format instead of the system date format.

Duration fields, however, export as the value stored in the database, which is an integer value of seconds.

6.2 XML

All Date and Time fields export as the value stored in the database.

6.3 PDF

All Date and Time fields (including Duration) export as their display value.

6.4 CSV

All Date and Time fields export as the value stored in the database.

Was this article helpful?
Yes, I found what I needed
No, I need more assistance