Results 1 to 4 of 4

Thread: [RESOLVED] [02/03] Weeks & Days

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Resolved [RESOLVED] [02/03] Weeks & Days

    Hello again.

    I have to make half weeks full weeks. So, basically what I've done with the help of the great jmcilhinney, is to get the specified number of days & weeks within a certain timeframe. Now, it produces a result saying I've got 9 weeks and 3 days (in that time period).
    What I'd like to do, is to round up / down the weeks, meaning, I do not want a remaining day.

    This is what I tried, but failed
    Code:
            Dim startDate As Date = dtSuggStartDate.Value
            Dim endDate As Date = startDate.AddMonths(Months)
            Dim interval As TimeSpan = endDate.Subtract(startDate)
            Dim weeks As Integer = interval.Days \ 7
            Dim days As Integer = interval.Days Mod 7
            Select Case days
                Case 1
                    days -= 1
                Case 2
                    days -= 2
                Case 3
                    days -= 3
                Case 4
                    days += 3
                    weeks += 1
                Case 5
                    days += 2
                    weeks += 1
                Case 6
                    days += 1
                    weeks += 1
                Case 7
                    days = 0
            End Select
            MessageBox.Show(String.Format("There are {0} weeks and {1} days between {2:d} and {3:d}", _
            weeks, _
            days, _
            startDate, _
            endDate))
    But now it shows I have 10 weeks and 7 days, instead of just showing I've got 11 weeks

    Can anyone help me out, please?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [02/03] Weeks & Days

    Any help please guys...

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Weeks & Days

    Try this
    Code:
    Dim startDate As Date = dtSuggStartDate.Value
            Dim endDate As Date = startDate.AddMonths(Months)
            Dim interval As TimeSpan = endDate.Subtract(startDate)
            Dim weeks As Integer = interval.Days \ 7
            Dim days As Integer = interval.Days Mod 7
            Select Case days
                Case 4, 5, 6
                    weeks += 1
            End Select

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Posts
    384

    Re: [02/03] Weeks & Days

    Thanx stanav, i appreciate.
    It seems like I was on the right track all along. I was so concerned about getting the Days to be seven, and not displaying, that I did not think logically. It's quite obvious to me now, that, by incrementing the week, I don't need to display the days, because the weeks are correct, full; and that's what I wanted.
    Thanx for sharing your knowledge!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width