Date difference required indays

Input
date_ETADate=09/01/2023(“MM/dd/yyyy”)
date_ATADate=08-Aug-2023

Output

Difference of days = 25days (Answer Expected)

I have written
DateDiff(DateInterval.Day,convert.ToDateTime(date_ETADate),convert.ToDateTime(date_ATADate)
and getting output =210days which is not expected

Hello!

You can use the DateDiff function.

Example:

Syntax: DateDiff(DateInterval, Date1,Date2)
Code: DateDiff(DateInterval.Day, “2016-01-30”,“2016-01-30”)

It will return the number of the days between the two dates as Integer Type.

Hope It helps!

Regards,
Usha

Use ParseExact not convert. You have to tell it the format of the strings it’s receiving. Convert doesn’t know what’s a month, what’s a day, etc

DateDiff(DateInterval.Day,DateTime.ParseExact(date_ETADate,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture),DateTime.ParseExact(date_ATADate,“dd-MMM-yyyy”,System.Globalization.CultureInfo.InvariantCulture))