Need to find the month difference between two date
09/31/2023 and 12/31/2023
The month diff is 3 months
Need to find the month difference between two date
09/31/2023 and 12/31/2023
The month diff is 3 months
Int32.Parse(DateDiff("m", DateTime.ParseExact("09/30/2023", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact("12/31/2023", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)).ToString())
Assign variables -->“09/30/2023”,“12/31/2023”
Hi @sruthesanju
You given one date which is 09/31/2023 in september month, there is only 30 days but you have given 31, change the date and follow the below,
Try this:
- Assign -> strInput1 = "09/30/2023"
- Assign -> strInput2 = "12/31/2023"
- Assign -> Output = DateDiff(DateInterval.Month, DateTime.ParseExact(Strinput1.ToString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture),DateTime.ParseExact(Strinput2.ToString, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture))
Note : Output is the Int64 datatype variable.
Check the below image for better understanding,
Hope it helps!!
Hi @sruthesanju
Try this:
Date1 = DateTime.ParseExact(dateString1, dateFormat, System.Globalization.CultureInfo.InvariantCulture)
Date2 = DateTime.ParseExact(dateString2, dateFormat, System.Globalization.CultureInfo.InvariantCulture)
DateDiffMonth = DateDiff(DateInterval.Month, Date1, Date2)
Hope it will helps you
Cheers!!
To find the month difference between two dates in UiPath, you can use VB.NET code within an ‘Assign’ activity. Here’s a step-by-step process:
DateTime
objects.Dim date1 As DateTime = DateTime.ParseExact(“09/30/2023”, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
Dim date2 As DateTime = DateTime.ParseExact(“12/31/2023”, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)
Note: The date “09/31/2023” is not valid since September has only 30 days. I’ve used “09/30/2023” instead.
2. Calculate Month Difference*: Use the DateDiff
function or subtract the months and account for the year difference.
Dim monthDiff As Int32 = ((date2.Year - date1.Year) * 12) + date2.Month - date1.Month
This will give you the difference in months between the two dates.
Depends on the precision which is needed
We ask for this detail as DateDiff is not handling the fractions:
EDITED: Fixing Typos, Added example of a fraction
Hi @sruthesanju
FirstDate = 09/31/2023
SecondDate = 12/31/2023
Create a Integer Variable and name as monthDifference.
Use Assign Activity
monthDifference = DateDiff(DateInterval.Month, FirstDate, SecondDate)
hey @sruthesanju
Dim date1 As DateTime = DateTime.ParseExact("09/31/2023", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
Dim date2 As DateTime = DateTime.ParseExact("12/31/2023", "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)
Dim monthDiff As Integer = Math.Abs(DateDiff(DateInterval.Month, date1, date2))