By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,474 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,474 IT Pros & Developers. It's quick & easy.

calculate weekdays

P: n/a
Is there a way to calculate the total number of weekdays when provided a
date?

Example:
If I have a start date of 7/11/2008 and I want to go out 10 days, I want to
get this:

6 weekdays
4 weekend days

Is something like this possible?
Jul 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Mike" <mo******@gmail.comwrote in message
news:eD****************@TK2MSFTNGP03.phx.gbl...
Is there a way to calculate the total number of weekdays when provided a
date?

Example:
If I have a start date of 7/11/2008 and I want to go out 10 days, I want
to get this:

6 weekdays
4 weekend days

Is something like this possible?
Simple enough with a bit of programming

Instantiate a DateTime variable from the starting date.

Set up a while loop which increases the DataTime variable using the
AddDays(1) method for the required number of iterations.

At each iteration, inspect the DataTime variable's DayOfWeek property. If it
equates to DayOfWeek.Saturday or DayOfWeek.Sunday, treat it differently from
the other days. Of course, not every culture considers Saturday and Sunday
to be the weekend, so you might need to check for that...

http://dotnetguts.blogspot.com/2007/...mespan-in.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 11 '08 #2

P: n/a
I'll give this a shot, Its for an internal app so Saturday and Sunday are
weekends.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:eL**************@TK2MSFTNGP06.phx.gbl...
"Mike" <mo******@gmail.comwrote in message
news:eD****************@TK2MSFTNGP03.phx.gbl...
>Is there a way to calculate the total number of weekdays when provided a
date?

Example:
If I have a start date of 7/11/2008 and I want to go out 10 days, I want
to get this:

6 weekdays
4 weekend days

Is something like this possible?

Simple enough with a bit of programming

Instantiate a DateTime variable from the starting date.

Set up a while loop which increases the DataTime variable using the
AddDays(1) method for the required number of iterations.

At each iteration, inspect the DataTime variable's DayOfWeek property. If
it equates to DayOfWeek.Saturday or DayOfWeek.Sunday, treat it differently
from the other days. Of course, not every culture considers Saturday and
Sunday to be the weekend, so you might need to check for that...

http://dotnetguts.blogspot.com/2007/...mespan-in.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 14 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.