Calculate Working Date Of Two DataFormate?????????????

Sabarimahesh
Posted by Sabarimahesh under C# category on | Points: 40 | Views : 1116
------------------------------------------------------------------------------------------------------------------------------------------------------------
This The Method in the class
------------------------------------------------------------------------------------------------------------------------------------------------------------

public static int Weekdays(DateTime dtmStart, DateTime dtmEnd)
{
// This function includes the start and end date in the count if they fall on a weekday
int dowStart = ((int)dtmStart.DayOfWeek == 0 ? 7 : (int)dtmStart.DayOfWeek);
int dowEnd = ((int)dtmEnd.DayOfWeek == 0 ? 7 : (int)dtmEnd.DayOfWeek);
TimeSpan tSpan = dtmEnd - dtmStart;
if (dowStart <= dowEnd)
{
return (((tSpan.Days / 7) * 5) + Math.Max((Math.Min((dowEnd + 1), 6) - dowStart), 0));
}
return (((tSpan.Days / 7) * 5) + Math.Min((dowEnd + 6) - Math.Min(dowStart, 6), 5));
}

----------------------------------------------------------------------------------------------------------------------------------------------------------
Button click
-----------------------------------------------------------------------------------------------------------------------------------------------------------

int nday = Weekdays(Convert.ToDateTime(TextBox1.Text.ToString()), Convert.ToDateTime(TextBox2.Text.ToString()));

TextBox3.Text=nday.ToString();

Comments or Responses

Login to post response