Date Difference by Month

Hello, i have some problem here. so i have two date :
a : 12/23/2019 00:00:00
b : DateTime.Now
i have already use (a-b).Days

the problem is, i have to know exactly how much month difference, if 23 dec it will be output 1 month if i run in 23 nov / 23 jan

Thankyou

1 Like

Hi @aliaga

You can use the DateDiff function.

Example:

Syntax: DateDiff(DateInterval, Date1,Date2)
Code: DateDiff(DateInterval.Day, “2016-01-30”,“2016-01-30”)

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

Hope It helps!

Regards,
Kommi Jeevan.

1 Like

Hello @kommijeevan,

it work for days, but i dont know how to get output in month not days

thankyou

Hope this expression would help you resolve this
(Convert.ToInt32(Datetime.ParseExact(“10/23/2019 00:00:00”,“MM/dd/yyyy hh:mm:ss”,system.Globalization.CultureInfo.InvariantCulture).ToString(“MM”))-datetime.Now.Month).ToString

This will give the difference of the month between the values
Cheers @aliaga

1 Like

@aliaga,

You can try like the following one, this will return you the difference in Months.

Math.Abs((firstDate.Month - secondDate.Month) + 12 * (firstDate.Year - secondDate.Year)).ToString

Code: DateDiff(DateInterval.Month, Convert.ToDateTime( “2016-01-30”),Convert.ToDateTime(“2016-05-30”))

1 Like

Dear @Palaniyappan,

Sorry For Slow Response, but i got this error.

image

1 Like

Aah
Sorry buddy that was my bad
The expression be like this
(Convert.ToInt32(Datetime.ParseExact(“10/23/2019 00:00:00”,“MM/dd/yyyy hh:mm:ss”,system.Globalization.CultureInfo.InvariantCulture).ToString(“MM”))-datetime.Now.Month).ToString

Cheers @aliaga

Hi @Palaniyappan,

Im so Sorry for asking you again. could you send me some sample in assign sequence?
i got an error like this


image

1 Like

here you go with an xaml
the expression used is
(Convert.ToInt32(Datetime.ParseExact(“10/23/2019 00:00:00”,“MM/dd/yyyy hh:mm:ss”,system.Globalization.CultureInfo.InvariantCulture).ToString(“MM”))-datetime.Now.Month).ToString
aliaga.zip (9.3 KB)

Cheers @aliaga

1 Like

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