How can I compare 2 dates in RPA Express?

Hi,
I saved 2 dates into string variables.
How can i compare those date? (greater than)
How can i add 1 month to the date?

Please provide some solution for me :smiley:

Hi @Zayn
You should first have both dates in date format (convert string to date:https://kb.workfusion.com/display/RPAe/Variables#Variables-ConvertStringtoDate ). Then you should be able to compare them.
I am not sure if date operations like adding 1 month is available yet: Date operations in Workfusion

2 Likes

I know the way to convert string to date.
But what is the way to compare both date?
Can you describe in details.
Still finding a way to add month in a faster way

I haven’t tried it but for the comparison I believe you could use the if-condition
IF date1 is greater than date2

1 Like

Hi @Zayn

There is no ready action for adding a month, but you can do it using a custom action.

@CustomScriptAction(
    input = ['date1'],
    output = 'date2'
)
def customeScript() {
    date2 = date1.plus(java.time.Period.ofMonths(1))
    }
2 Likes

@ashapkina thanks for your answer.

1 Like

How about comparing two dates?

As @timriewe mentioned you can do it with the help of If-Else condition

The date comparison doesn’t work when the 2 dates fall in different years.
In my scenario i have to capture a date and then add 30 days to it which i did using the custom script, and then compare if the date <= Current Date

This comparison fails when the dates fall in different years.
For e.g. Date1 = 12/30/2019 & Date2 = 12/30 + 30 days = 1/29/2020
Obviously Date2 is > Date1 but for some reason it calculates Date1>Date2

Is that a known issue in RPA/SPA?

Hi @aroy do you store these dates in DateTime type of variables? Or are they stored as Strings?

Hi,
I’m storing them in a string variable.

To compare dates, you need to reformat them to DateTime variables using Date Format action.

Thank you so much.
It worked

1 Like

Format the date in YYYYMMDD format if you want to compare using string format

1 Like

Sorry but it didn’t work.
Only the DateTime variable comparison works.