Solved

Unable to Find DifferenceBetweenTwoDates

  • 20 December 2023
  • 2 replies
  • 58 views

Badge

I am unable to find “DifferenceBetweenTwoDates” under actions.

Please advise how to get that.

This is my control room url.

https://community.cloud.automationanywhere.digital/

 

icon

Best answer by Syed Zaman Akhtar 28 December 2023, 12:51

View original

2 replies

Userlevel 3
Badge +7

Hi @MadhuDampuri ,

 

You can use below python script in python commands to find the difference between 2 dates. The input date format should be in YYY-mm-DD (ex: 2023-12-31). The output will be in days.

 

from datetime import datetime

def date_diff_in_days(date_range):
    # Split the input string into two dates
    dates = date_range.split('//')

    # Convert the dates to datetime objects
    date1 = datetime.strptime(dates[0], "%Y-%m-%d")
    date2 = datetime.strptime(dates[1], "%Y-%m-%d")

    # Calculate the difference in days
    date_diff = abs((date2 - date1).days)

    return date_diff

Badge +3

Use the VB script for calculating the difference:

 

I have converted the format as well coz of the way VBScript handles and interprets date values. In VBScript, the default date format is typically mm/dd/yyyy, which is in line with the date format commonly usd in the US.

When you provide a date string to VBScript for date-related operations, like calculating the difference between two dates, VBScript attempts to parse this string according to its default date format.

Reply