Compare two datetime variables - retrieve month differences

Hello Everybody.
Simple question i think for you but i dont’ find any strong solution until now.
I have two variables already in datetime format.
date_1 = 01.01.2022
date_2 = 14.10.2022

My goal is to find if date 1 is previous month compared to date2

How can i achieve this goal?

Ex: date1 = 01.01.2022 is previous month compared to date2
date2 = 01.12.2021 is previous month compared to date2
date3 = 01.10.2021 is previous month compared to date2
date4 = 01.10.2022 is current month compared to date2

Thanks a lot guys!!

Hi @l.sambinelli,

Can you check out below code. (1.6 KB)


Mark it as solution if it resolves your issue.

Hi @l.sambinelli
Find the below solution (1.6 KB)

we can parse the date string into a date by following (kindly note some variations on the smaples)

and can use the dateDiff method for the checks (position of the parameters counts)

Kindly note: DateDiff will not return fractions of a unit and can have side effects e.g. we want to retrieve the information of “Complete of X” X - year, month…

thanks but i dont’ have any DateDiff function in my uipath (

thanks. Result its’ not ok.
Because if you compare first date like : 01-12-2021 to today with your code the result is false like “current” month


the screenshots from the answer were done within immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

so it is done and available within UiPath / VB.Net

Have a look on the docu

Maybe you will prefer to use the full qualified method name:


Also check following and add if it is missing:

Hi @l.sambinelli,

Can you explain what exactly you want as output.

Let suppose date2 is current date and you want to check the first date is earlier month to current date that means it can be december of 2021

date2 is current date and you want months which are from january to current month thats is october.

Hi @l.sambinelli,

Can you please check out below solution, hope this one will definitely resolve your issue. (1.5 KB)