Extract Date

Extracts date and time values from an input text.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

The Extract Date command analyzes the input text to look for date and time values on it. A date and time value is any reference to it on a timeline, such as December 5, Dec 5, last week, next week, last month, or next month.

This command returns the date and time value with the yyyy-MM-dd HH:mm:ss format. Mapping returns the date according to the operating system's date and time format.

The results that this command returns might vary according to the selected NLP provider. For more information, see Setting an NLP provider.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

extractDate --culture(Culture) --text(String) (List<DateTime>)=values (DateTime)=first (DataTable)=valuesmapping (Boolean)=success

Input parameter

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Language culture Required Text, Culture The language that is used to analyze the input text.

If you define the language manually, make sure to enter only supported language codes.

See the culture parameter options for supported languages.
Text text Required Text The input text.

culture parameter options

The following table displays the options available for the culture input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name Description Supported provider
ar ar Arabic Watson NLP
zh-CN zh-CN Chinese (Simplified) Watson NLP
zh-TW zh-TW Chinese (Traditional) Watson NLP
cs cs Czech Watson NLP
da da Danish Watson NLP
nl nl Dutch Watson NLP
de-DE de-DE German Watson NLP
en-US en-US English Legacy and Watson NLP
fi fi Finnish Watson NLP
fr-FR fr-FR French (France) Watson NLP
fr-CA fr-CA French (Canada) Watson NLP
he he Hebrew Watson NLP
it-IT it-IT Italian Watson NLP
ja-JP ja-JP Japanese Watson NLP
ko-KR ko-KR Korean Watson NLP
nb nb Norwegian Bokmal Watson NLP
nn nn Norwegian Nynorsk Watson NLP
pt-BR pt-BR Portuguese (Brazil) Legacy and Watson NLP
pt-PT pt-PT Portuguese (Portugal) Legacy and Watson NLP
pl pl Polish Watson NLP
ro ro Romanian Watson NLP
ru-RU ru-RU Russian Watson NLP
sk sk Slovak Watson NLP
es-ES es-ES Spanish Watson NLP
sv sv Swedish Watson NLP
tr tr Turkish Watson NLP

Obsolete input parameter

The following table displays the obselete input parameters in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label, in which version it was deprecated, and the command's behavior on versions up to the version it was deprecated.

Designer mode label Script mode name Version Description
Timezone Offset timezoneoffset 23.0.8 For versions up to 23.0.7: The offset value that the command considers to adjust the dates found. By default, the value is blank, which maps to the computer's time zone.
The offset value ranges from -24 to +24. If the offset value is 0, the command considers the GMT time zone.

From version 23.0.8 onwards: The offset value that the command considers to adjust the found dates. The field is blank by default, which is equivalent to 0, no offset value is applied.

Output parameter

Designer mode label Script mode name Accepted variable types Description
Values values List<Date Time> Returns a list of date and time values that are extracted from the input text.

Date and time values in the list are formatted as yyyy-MM-dd HH:mm:ss.
First value first Date Time Returns the first occurrence of a date and time value in the input text. This value is formatted as yyyy-MM-dd HH:mm:ss.
Values mapping valuesmapping Data Table Returns the date and time mappings.

See the valuesmapping parameter options section for details.
Success success Boolean Returns True if the command successfully extracts the date and time value, or False otherwise.

valuesmapping parameter options

This parameter returns a data table that contains the occurrence of each date and time value that is extracted from the input text.

The following list shows the mapped values:

  • The index value in the list of extracted addresses. Index values start at 1.
  • Position in number of characters where the value was found in the text.
  • Length of the extracted value.
  • Text from which the date was extracted.
  • Value that is formatted as MM/dd/yyyy HH:mm:ss. The format might change according to the operating system's language.

Example

Example 1: The Extract Date command assigns the input text to a variable, extracts the dates presented on the input text, and returns the list of values, the first value, and the values mapping.

defVar --name sentence --type String
defVar --name listExtractedValues --type List --innertype DateTime
defVar --name firstDateTime --type DateTime
defVar --name valuesMapping --type DataTable
defVar --name valueExtracted --type Boolean
// Assigns the input text to a variable.
setVar --name "${sentence}" --value "Order 1, created: 02/08/2023 \r\nOrder 2, created: 04/08/2023"
// Extracts the dates within the input text. 
extractDate --culture "en-US" --timezoneoffset 0 --text "${sentence}" listExtractedValues=values firstDateTime=first valuesMapping=valuesmapping valueExtracted=success
// Logs the extracted value.
logMessage --message "Check the output from the sentence used by this example:\r\n\r\nLisf of values: ${listExtractedValues}\r\nFirst value: ${firstDateTime}\r\nValues mapping: ${valuesMapping}\r\nValue extracted with success: ${valueExtracted}" --type "Info"
// List of values: [2023-02-08 00:00:00,2023-04-08 00:00:00]
// First value: 2023-02-08 00:00:00
// Values mapping: 1, 19, 10, 02/08/2023, 2/8/2023 12:00:00 AM
// 2, 50, 10, 04/08/2023, 4/8/2023 12:00:00 AM 

Example 2: The following code example demonstrates how to use the Extract Date command to analyze the input text. It looks for parts of text that corresponds to a date and time value, and as result it returns this value in a format for representing dates and time, like yyyy-MM-dd HH:mm:ss.

defVar --name sentence --type String
defVar --name listExtractedValues --type List --innertype DateTime
defVar --name firstDateTime --type DateTime
defVar --name valuesMapping --type DataTable
defVar --name valueExtracted --type Boolean
// Assigns the input text to the "${sentence}" variable.
setVar --name "${sentence}" --value "Finance automation got a kick-start in the 1990s, when MIT researchers developed the optical character recognition (OCR) technology for reading the handwritten parts of checks with high speed and accuracy. Today’s consumers have more options than ever for financial services, and they have high expectations for personalized services, fast processing times and responsive support."
// Extracts the dates within the input text. 
extractDate --culture "en-US" --text "${sentence}" firstDateTime=first valuesMapping=valuesmapping valueExtracted=success listExtractedValues=values
// Logs the extracted value.
logMessage --message "Check the output from the sentence used by this example:\r\n\r\nLisf of values: ${listExtractedValues}\r\nFirst value: ${firstDateTime}\r\nValues mapping: ${valuesMapping}\r\nValue extracted with success: ${valueExtracted}" --type "Info"
//  You can get an output in the following format:
//
// Lisf of values: [2022-05-10 15:58:15]
// First value: 2022-05-10 15:58:15
// Values mapping: 1, 206, 5, Today, 5/10/2022 6:58:15 PM
// Value extracted with success: True

Note: This example won't properly work with the Watson NLP provider due to the limitations of the command.

Limitations

When using the Watson NLP provider, the command will identify textual date expressions and return them as results, but will not convert them to Date Time values.