I’m trying to calculate the difference between two dates but I kept getting this error message and couldn’t figure out why. I have been reading from the forum and don’t know what i did wrong. Thank you so much!


I’m trying to calculate the difference between two dates but I kept getting this error message and couldn’t figure out why. I have been reading from the forum and don’t know what i did wrong. Thank you so much!


You shouldn’t name a variable DateDiff as DateDiff is a method of the datetime class. Change the name of your variable and see if the error goes away.
Changed it but the error still there

DateTime.ParseExact(“2024-05-10”, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture)
Replace “2024-05-10” with the string representation of your desired date.
otherDate - today
it works. Thanks so much!
You don’t have to do all that. It’s creating extra variables you don’t need. It can all be done in one expression the way you originally had it.
Looking back at your original post, you are converting DateTime.Now to string and then converting it back to datetime. This is redundant.
Use this as your expression to assign to NumberofDays.
DateDiff(DateInterval.Day,DateTime.ParseExact(date1,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture),Now)
Also if you are only using NumberofDays once (ie in an If condition, entering it into a field, etc) then you don’t need this variable. You can just directly use that expression in the If condition, entering it into the field, etc.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.