Handle Date and Time with Robots

Starting with Kofax RPA 11.3.0, you can extract dates and time from typical formats into a uniform date and time format, create and assign Date, Time, and DateTime variables, compare and convert dates and time, and more.

This topic provides general information about the feature and includes links to other topics in this help that contain detailed descriptions for handling date and time with Robots.

To work with date and time, the following functionality is available:

Types

The Date type is a type that represents a date without a reference to a time or a time zone. A variable of type Date has the default value of 1601-01-01.

The Time type is a type that represents a time without a reference to a date and a time zone. A variable of type Time has the default value of 00:00:00.

The DateTime type is a type that represents a date and a time with a time zone in the ISO-8601 calendar system, which is essentially a Date and a Time value with a time zone. The default value for a DateTime variable is composed of the default types of its Date and Time components, with the default time zone corresponding the location where the Robot runs.

These types correspond to the simple type Date of Basic Engine Robots. To use these types, you first need to create a complex type with an attribute of type Date. Then, you need to specify the Field Type in Record Type to be either Date, Time, or DateTime (default). For additional instructions, see Date, Time, and DateTime Record Field Types. Also, you can add a variable of Date, Time, or DateTime type directly in the Robot Editor to be used inside the Robot, but in this case, the variable result value will not be transferred to the Basic Engine Robot.

The Date, Time, and DateTime values are reflected in the State pane under the Variables section, as shown here. When you are editing a Robot, you can temporarily change the value of a variable in the State pane by double-clicking the value and entering a new one. Similar to other values, you can change individual parts of Date, Time, and DateTime values, such as year, hour, offset, and so on.

Converter steps

Two converter steps are available to handle date and time with Robots:

  • The Extract DateTime step converts a textual representation into a Date, Time, or DateTime value.

  • The Format DateTime step converts a Date, Time, or DateTime value into a Text value.

Functions

When using the product, you can get a complete list of the available functions directly in the Expression editor by pressing Ctrl-Space. For a detailed description of the available functions, see the Expressions topic.

Each type, Date, Time, and DateTime, offers several sets of functions to help you access its components:

  • Date: year, month, and day.

  • Time: hour, minute, second, and nanosecond.

  • DateTime: date, time, offset, and zoneID.

Note that these components are not field values and, therefore, cannot be accessed as fields in an expression or set with a field in an Assign step.

With the other functions, you can create values of the respective type and convert values of that type into text. For example, you can change the value of a DateTime component using the with functions; add or subtract a number of years, months or days with the plus and minus functions; convert the value into a textual representation using the text functions, and so on.

Examples

  • The year(Date) function returns the year of the current date.

    year(date(2022, 3, 4)) returns year = 2022.

  • The hour(Time) function returns the hour of the current time.

    hour(time(14, 50, 45)) returns hour = 14.

  • The withDay(Date, Integer) function returns a copy of the date with the day altered.

    date(2022, 3, 4).withDay(10) returns year = 2022, month = 3, day = 10

  • The plusDays(Date, Integer) function returns a copy of the date with the specified number of days added.

    date(2022, 3, 4).plusDays(70) returns year = 2022, month = 5, day = 13.

  • The text(DateTime, Text, Text) function returns the textual representation of the date and time of DateTime matching the specified pattern and locale (combination of a language code and a country code separated by a hyphen).

    Given the DateTime of 2021-12-20T00:30:00+03:00, text("EEEE MMM d yy HH:mm", "en-US") returns "Monday Dec 20 21 00:30"

Work with time zones

A set of functions is available to work with time zones. For example, you can get the current time zone and change the time zone. Two properties are relevant for time zones: zoneID and Offset.

zoneID

zoneID is used to identify a time zone, such as "Europe/Paris" or "MET." This property can be useful in a situation where the daylight saving time must be taken into account or a DateTime value must be converted from one time zone to another. The zone ID and the offset are interrelated, and changing one may also change the other.

Offset
Offset is used to identify a time zone offset from Greenwich/UTC, such as +01:00 or -05:00. Offset can have the following formats:
  • Z - for UTC

  • +h

  • +hh

  • +hh:mm

  • -hh:mm

  • +hhmm

  • -hhmm

  • +hh:mm:ss

  • -hh:mm:ss

  • +hhmmss

  • -hhmmss

Setting Offset changes zoneID to UTC followed by the offset unless the offset is 0 or Z. For example, setting the offset to +00 results in the zone ID of UTC, while setting the offset to +05 results in the zone ID of UTC +05:00.

Also, setting the offset or zone ID on a DateTime value results in a DateTime value representing the same instance with the new zone, that is, the date and time might change. This can be done with the functions withzoneID and withOffset.

Changing the time zone without changing the date and time can be done by creating a new DateTime value as follows:

dateTime(dateTime1.date(), dateTime1.time(), “Europe/Paris”)

Setting the offset or zone ID from the State view changes the zone ID or offset, respectively, so they are consistent with each other, but the date and time remain unchanged.