Not able to get the date difference

Hello Community
I have getting this problem while finding date diffrence between 2 days i assigned variable to int64 and passed the below vb expression but getting the error

DateDiff(DateInterval.Day,CDate(expiry_date.ToString(“MM/dd/yyyy”)),Cdate(DateTime.ParseExact(Noticedate.Trim,“dd/MM/yy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)))

Error: AP1_Reference.xaml: BC30512: Option Strict On disallows implicit conversions from ‘String’ to ‘IFormatProvider’. The selected value is incompatible with the property type.
Thank you in advance

when expiry_date is already of DataType: DateTime we dont need a double conversion of toString->ParseAgain to DateTime with CDate

so we we recommend to simplify the statement first

UPD1 - enhanced explanation

Hi @madhavraichur25

Try the syntax below:

DateDiff(DateInterval.Day, CDate(expiry_date.ToString("MM/dd/yyyy")), DateTime.ParseExact(Noticedate.Trim, "dd/MM/yy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM/dd/yyyy"))

Regards

Hi @madhavraichur25 ,

CInt(DateDiff(DateInterval.Day, DateTime.ParseExact(expiry_date, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(NoticeDate, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture)))

Thanks ,

Sneha

If expiry_date is already datetime there is no reason to convert it to string and then CDate it. It’s already a datetime.

Putting CDate around DateTime.ParseExact is redundant. ParseExact already returns a datetime.

DateDiff(DateInterval.Day,expiry_date,DateTime.ParseExact(Noticedate.Trim,“dd/MM/yy”,System.Globalization.CultureInfo.InvariantCulture))

Hey @madhavraichur25

Have you got the Solution? If not then kindly debug the code till the error point go to immediate panel put above mentioned variables i.e, expiry_date, Noticedate and attach a screenshot of immediate panel here. So, that we can get clear understandings of date formats!

Regards,
Ajay Mishra