i am working in windows applicatio, i have two fields startdate and duration, i want to calculate the terminal date,but i get the duration to be added to start date but it will not add sundays to startdate;i am attaching my code, plz help me wat editing i have to do in my code
ma code:
public string FindTerminationDate(DateTime dtStartDate, int iDuration, string strDurationType)
{
string strTermination="";
if (strDurationType == "Days")
{
return strTermination = dtStartDate.AddDays(iDuration).ToString("dd/MMM/yyyy");
}
else if (strDurationType == "Months")
{
return strTermination = dtStartDate.AddMonths(iDuration).ToString("dd/MMM/yyyy");
}
else if (strDurationType == "Years")
{
return strTermination = dtStartDate.AddYears(iDuration).ToString("dd/MMM/yyyy");
}
return strTermination;
}
Loading
Dorababu MekaPosted Sep 18, 2012, 8:08 AM
public static DateTime daysWithOutSunday(DateTime dtStartDate , double duration)
{
int days= (int) dtStartDate.DayOfWeek;
double temp = duration + days + 1;
if ( days != 0) temp--;
DateTime dtTerminal= dtStartDate.AddDays(
Math.Floor(temp / 6) * 2 - days + temp
- 2 * Convert.ToInt32(temp % 6 == 0));
return dtTerminal ;
}