calculate weekdays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    calculate weekdays

    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?


  • Mark Rae [MVP]

    #2
    Re: calculate weekdays

    "Mike" <moveaway@gmail .comwrote in message
    news:eDH%23Fn44 IHA.3796@TK2MSF TNGP03.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.Satur day or DayOfWeek.Sunda y, 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...

    Understanding DateTime and TimeSpan in .Net through real time example //Creating Two Instance of DateTime DateTime dt1 = new DateTime(); Dat...



    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Mike

      #3
      Re: calculate weekdays

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

      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:eL8Jcy44IH A.5048@TK2MSFTN GP06.phx.gbl...
      "Mike" <moveaway@gmail .comwrote in message
      news:eDH%23Fn44 IHA.3796@TK2MSF TNGP03.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.Satur day or DayOfWeek.Sunda y, 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...
      >
      Understanding DateTime and TimeSpan in .Net through real time example //Creating Two Instance of DateTime DateTime dt1 = new DateTime(); Dat...

      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      Working...