I am using c#.
I have a problem of finding the difference between 2 dates in terms of year,month and day.
For example Finding the difference of 2 dates(mm/dd/yy).

I used the following code

int year=date2.Year-date1.Year;
int month=date2.Month-date1.Month;
int day=date2.Day-date1.Day;

The output I am getting is
1 year 3 months 2 days.

But the actual output is

0 year 3 months 2 days.

How will I solve this?please help me..


it will do 2011-2010
difference is 1 right?

I want to get it as
0 year 3 months 2 days.
Can anyone give new code for that?

use asp.net datediff function for finding date difference between two dates

DateDiff( DateInterval, Time1, Time2, [firstDayOfWeek], [firstDayOfYear] )

can u please explain the parameters of the function?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.