-
public void getDays()
{
DateTime dt1 = new DateTime(2010, 01, 01);//Initialize a date
DateTime dt2 = DateTime.Now;//Get today’s date
TimeSpan ts1 = dt1.Subtract(dt2);//TimeSpan gets the time interval between dt1 and dt2
int countday = ts1.Days;//Get the total number of days between two dates
int weekday = 0;//working day
//Loop to deduct weekends from the total number of days
for (int i = 0; i < countday; i++)
{
DateTime tempdt = dt1.Date.AddDays(i);
if (tempdt.DayOfWeek != System.DayOfWeek.Saturday && tempdt.DayOfWeek != System.DayOfWeek.Sunday)
{
weekday++;
}
}
Response.Write("Total number of days: " + countday.ToString());
Response.Write("Workday: " + weekday.ToString());