13,249,174 members (35,569 online)
Rate this:
See more:
Hello Sir,

I have calculated no of days between two days like that given below:

```DateTime startdate = new DateTime();

startdate =Convert.ToDateTime(DateMontYearToYearMonthDate(stdate.Text));

DateTime Enddate = new DateTime();

Enddate = Convert.ToDateTime(DateMontYearToYearMonthDate(endate.Text));

TimeSpan nod = (Enddate - startdate);

numdays.Text = nod.TotalDays.ToString();```

but i need to calculate no of days between two dates except sunday?

how to do this in c#.if u answer it will more help for me to do this.thanks in advance.
Posted 17-Jan-13 20:26pm
Updated 17-Jan-13 21:14pm
v2

Rate this:

## Solution 1

DateTime startdate = Convert.ToDateTime("01/13/2013");
DateTime enddate = Convert.ToDateTime("01/18/2013");
int count = 0;
while (startdate != enddate)
{
if (startdate.DayOfWeek.CompareTo(DayOfWeek.Sunday) != 0)
{
count++;
}
else
{
}
}
MessageBox.Show("no of days"+count);
Rate this:

## Solution 2

There is a solution here: http://stackoverflow.com/questions/1617049/calculate-the-number-of-business-days-between-two-dates[^] which will need a small change to include Saturdays - it assumes a 5 day working week, where you have a six day.

But please, you don't need to convert like that!
```startdate =Convert.ToDateTime(DateMontYearToYearMonthDate(stdate.Text));
```

Don't play with text: look at using DateTime.TryParseExact[^] instead - it lets you specify exactly what the input string should look like, and convert it in a single operation (or report an error if the user entered a bad date).

Top Experts
Last 24hrsThis month
 phil.o 90 ppolymorphe 55 OriginalGriff 50 Ralf Meier 35 CHill60 30
 OriginalGriff 3,454 Karthik Bangalore 1,992 ppolymorphe 1,399 Dave Kreskowiak 1,276 CPallini 1,215