hi friends i am having two drop down lists one will be for hiredate and one more for the current date and i want the datediff between hiredate and current date in terms of year and months
for eg :(if total is 34 months) then i want as output is 2 years and 10 months
Loading
Deepthi AravindPosted Oct 6, 2010, 2:42 AM
select datediff(MM,@FromDate,@ToDate)/12
select datediff(MM,@FromDate,@ToDate)%12
First line will return the count of years and second one returns the count of months
Try this...
Mamta MPosted Jul 28, 2010, 6:42 AM
double n = (newdate - firstdate).TotalDays;
var years = n/365.0;
var actualdays = 365 * Convert.ToInt16(years);
double months = 0.0;
if (n != actualdays)
{
months = (n-actualdays)/30.000;
}
Now,
Convert.ToInt16(years) will give you the years in int
Convert.ToInt16 (months) will give you the months in int
Hope that helped you.