DateDiff(Inteverval.Month)

Converted date:
DateTime.ParseExact(in_TransactionItem(“DateTime.String”).ToString,“dd-MM-yyyy”,NL_Formaat)

Assign
DateVariable2 = DateTime.ParseExact(in_TransactionItem(“DateTime.String”).ToString,“dd-MM-yyyy”,NL_Formaat).

Now I want to calclulate de difference in months between
DateTime.now and DateTimeVariable2.

DateDiff(DateInterval.Month, DateTime.now, DateTimeVariable2)
The result must have been 4 months
I got 0 months.

Can anybody help me to solve this.

Thanks

can you try to log these 2 variables (DateVariable2 / DateTime.now) and share the results…

DateDiff(DateInterval.Month, “Date1”,“Date2”) will definitely works

Have you converted both the values which you gonna manipulate to Date format?

Sorry it didn’t help.

Nevertheless thanks for your help

ParseExact because convert to Datetime didn’t work.

Debug:

  • Now gives the value 20-02-2020 15:03:12
  • DateimeVariable2 gives the value 30-10-2019 00:00:00

I also tried to firstly convert Now to string and afterwards DateTime.ParseExact to get equal values.
That didn’t work neither.

instead of convert Now to string use convert.ToDateTime(“String”).ToShortDateString

in your case i think Short date will help you

actually the result would be -4 not 4, and you certainly have a variable problem there, if it is 0 as result then you are maybe passing the same date in both variables or dates closer than a month…

Try with only DateTime.Parse(DateVariable) without providing the format as “dd-MM-yyyy”. It should work.

then he will have an parse error as he does have a string with a different format…