Calculate Date Difference

Calculates the time interval between two dates in days, hours, minutes, and seconds.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Calculates the time interval between two dates in days, hours, minutes, and seconds, returning the difference in a variable.

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.

dateDifference --subtractdate(DateTime) --fromdate(DateTime) (TimeSpan)=value

Input parameters

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
Subtract subtractdate Required Date Time, Date Date Time variable to be subtracted from the value entered in the From parameter to calculate the difference.
From fromdate Required Date Time, Date Date Time variable of where the value is subtracted.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Timespan value Time Span Difference in days, hours, minutes, and seconds between two dates. Period (.) separates days from hours, colon (: ) separates hours from minutes and minutes from seconds.

Example

The following code calculates the difference between two dates.

defVar --name subtractThisDate --type DateTime --value "2013-02-06 13:02:03"
defVar --name fromThisDate --type DateTime --value "2015-02-06 12:22:03"
defVar --name dateDifference --type TimeSpan
dateDifference --subtractdate ${subtractThisDate} --fromdate ${fromThisDate} dateDifference=value
logMessage --message "${dateDifference}" --type "Info"
// Calculates the difference between dates ("2013-02-06 13:02:03" "2015-02-06 12:22:03").
// Difference: (729.23:20:00).