How to find difference between two date

Dear all,

I have to find the difference between the two date’s months and year.

Input String: “2021-09-02”, “2022-02-12”

Now I want the following list as the difference between two date

Sept-2021
Oct-2021
Nov-2021
Dec-2021
Jan-2022
Feb-2022

Kindly help to find the solution.

Best Regards,
Vrushali

Hi @Vrushali_Gave
can u try the sample syntax below

DateDifference = DateDiff(DateInterval.Day, Convert.todatetime(“04-25-2021”), Convert.todatetime(“01-27-2022”))
Also change DateDifference variable to Int

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

1 Like

@nikhil.girish Thank you for the response

I want a month and year list from two date difference

you could use a do while loop?

Start with your first date - then increment the month by 1 and add it to your list of strings.

I would convert the strings to date first as @nikhil.girish suggested.
Convert.todatetime(“04-25-2021”)

Your exit condition would be if your last date added matches your end date.
I would also check just months rather than dates.
Datetime.Month

1 Like

Hi @Vrushali_Gave

DateDiff(DateInterval.Month, Convert.ToDateTime( “2016-01-30”),Convert.ToDateTime(“2016-05-30”)) — for month

1 Like

Hope below link helps to solve the issue…

2 Likes

@Vrushali_Gave ,

Check this xaml, it will give you the result you are looking for.
GetMonthsBetweenDates.xaml (6.4 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.