Marcelino
(Marcelino Alvarez)
February 20, 2020, 12:06pm
1
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
GBK
(GBK)
February 20, 2020, 12:13pm
2
Marcelino:
ParseExact
can you try to log these 2 variables (DateVariable2 / DateTime.now) and share the results…
karthick
(Karthick)
February 20, 2020, 12:32pm
3
DateDiff(DateInterval.Month, “Date1”,“Date2”) will definitely works
Have you converted both the values which you gonna manipulate to Date format?
Marcelino
(Marcelino Alvarez)
February 20, 2020, 1:59pm
4
Sorry it didn’t help.
Nevertheless thanks for your help
Marcelino
(Marcelino Alvarez)
February 20, 2020, 2:09pm
5
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.
karthick
(Karthick)
February 20, 2020, 2:11pm
6
instead of convert Now to string use convert.ToDateTime(“String”).ToShortDateString
in your case i think Short date will help you
bcorrea
(Bruno Correa)
February 20, 2020, 2:17pm
7
Marcelino:
20-02-2020
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…
UiJack
(Ui Jack)
February 20, 2020, 2:34pm
8
Try with only DateTime.Parse(DateVariable) without providing the format as “dd-MM-yyyy”. It should work.
bcorrea
(Bruno Correa)
February 20, 2020, 2:35pm
9
then he will have an parse error as he does have a string with a different format…