12,997,441 members (60,251 online)
Rate this:
See more:
how to get datediff between two dates in months in asp.net using C#
Posted 18-Nov-12 19:41pm

Rate this:

v2
Rate this:

## Solution 2

You can try this simple method:

```DateTime Date1=new DateTime(); DateTime Date2=new DateTime();

int Value = (Date1.Year * 12 + Date1.Month) - (Date2.Year * 12 + Date2.Month);```
Rate this:

Rate this:

## Solution 4

I think this is an incomplete question. You should give an example of two dates and tell how you want the output.

Because, its not clear if it is 15 days of difference between two dates, How do you want the output? 0 months ? or 0.5 months? If you want 0.5 months then what if the month is February? And if it leap-year !

If you want difference in terms of 0 years, 0 months, 15 days kind then you have to specify accordingly.
```DateTime date1 = new DateTime(2009, 8, 1);
DateTime date2 = new DateTime(2009, 9, 5);

int Days  = date2.Year - date1.Year;
int Months = date2.Month - date1.Month;
int Years = date2.Day - date1.Day;```

This will give the output as I explained.

If you want just days then what _TR_ gave links will work i.e. subtract and then gets days and divide the output by 30 !

Hope this helps.
Thanks
Milind

Top Experts
Last 24hrsThis month
 ppolymorphe 295 RickZeeland 255 OriginalGriff 255 F-ES Sitecore 130 Kornfeld Eliyahu Peter 85
 OriginalGriff 4,442 ppolymorphe 2,242 Kornfeld Eliyahu Peter 1,973 RickZeeland 1,901 Richard Deeming 1,543