12,445,916 members (64,907 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
 OriginalGriff 370 Maciej Los 346 CPallini 245 Karthik Bangalore 240 Richard Deeming 200
 OriginalGriff 5,493 Karthik Bangalore 3,252 ppolymorphe 2,997 Maciej Los 2,802 Richard Deeming 2,385