|
-
Aug 13th, 2007, 09:27 AM
#1
Thread Starter
Hyperactive Member
[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?
-
Aug 13th, 2007, 10:47 AM
#2
Thread Starter
Hyperactive Member
Re: [02/03] Weeks & Days
Any help please guys...
-
Aug 13th, 2007, 12:07 PM
#3
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
-
Aug 14th, 2007, 03:39 AM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|