How to calculate Date difference

I have below code
DateDiff(DateInterval.Day, Convert.todatetime(System_Date), Convert.todatetime(BirthDay_Date)).ToString

System date is 06/12 and Birthday_Date is 07/12.
i need to get the answer as 1 but am getting 30. How it is possible.
Can anyone help me regarding this

To calculate the difference in days correctly, ensure that the dates are in the format MM/dd/yyyy and use the following expression in UiPath:

DateDiff(DateInterval.Day, DateTime.ParseExact(System_Date, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(BirthDay_Date, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture)).ToString()

Regards,
Vinit Mhatre

Yes. it is in “dd/MM” format.

just i wand to get the difference date and month. Ex: todays date is 06/12/2023 and birthday date is 07/12/1997. i need to get the difference 1

Hello @Vanitha_VS

Assign activity:
Left side: systemDate
Right side: DateTime.ParseExact(System_Date, “MM/dd”, CultureInfo.InvariantCulture)

Assign activity:
Left side: birthdayDate
Right side: DateTime.ParseExact(BirthDay_Date, “MM/dd”, CultureInfo.InvariantCulture)

Assign activity:
Left side: daysDifference
Right side: DateDiff(DateInterval.Day, systemDate, birthdayDate).ToString

Thanks & Cheers!!!

2 Likes

Hi,

Can you try the following expression?

DateDiff(DateInterval.Day, DateTime.ParseExact(System_Date,"d/M",System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(Birthday_Date,"d/M",System.Globalization.CultureInfo.InvariantCulture)).ToString

However, it will return 364 if input data are 1/1 and 31/12 because of missing year.

Regards,

Hi @Vanitha_VS

Math.Abs((DateTime.ParseExact("07/12", "dd/MM", CultureInfo.InvariantCulture) - DateTime.ParseExact("06/12", "dd/MM", CultureInfo.InvariantCulture)).TotalDays).ToString

@Vanitha_VS

Try this :

DateDiff(DateInterval.Day, DateTime.ParseExact(System_Date, “dd/MM”, CultureInfo.InvariantCulture), DateTime.ParseExact(BirthDay_Date, “dd/MM”, CultureInfo.InvariantCulture)).ToString

1 Like

@Vanitha_VS

try this

Ensure that the date format is correctly interpreted. In some regions, the date format is MM/DD/YYYY, while in others, it’s DD/MM/YYYY. Make sure your dates are formatted consistently.

DateDiff(DateInterval.Day, Date.ParseExact(System_Date, "MM/dd", Globalization.CultureInfo.InvariantCulture), Date.ParseExact(BirthDay_Date, "MM/dd", Globalization.CultureInfo.InvariantCulture)).ToString

cheers!!!

Hi @Vanitha_VS

Use below expression for getting the Days Count

DateDiff(DateInterval.Day, DateTime.ParseExact(System_Date,“d/M”,System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(BirthDay_Date,“d/M”,System.Globalization.CultureInfo.InvariantCulture)).ToString

Hope it’ll helps you.

Cheers!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.