automatically selecting dates

yami

Newcomer
Joined
Aug 14, 2003
Messages
5
I am writing a VB windows program which has a function that returns the date of the second wednesday of the current month as well as the next two months, but without needing to actually look at a calendar.

I'm not quite sure how to accomplish this. Perhaps using a calendar control? Any suggestions would be greatly appreciated!
 
Try this out and see how it fits... I added some comments so hopefully you can see what I was doing. :)
Visual Basic:
Dim R As DateTime = DateTime.Now
Dim TargDate As System.DayOfWeek = DayOfWeek.Monday
'My new datetime instance
Dim NextDay As Integer
R = R.AddDays(1 - R.Day)
'Move R to the first day of the month
NextDay = (7 + TargDate - R.DayOfWeek) Mod 7
'I derived this formula myself :}
R = R.AddDays(NextDay + 7)
'Add this nextday and a week for you.
MessageBox.Show(R.ToString)
'The result is in R (of course)
 
Back
Top