range in calendar

jvcoach23

Well-known member
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
need some help and advice.

I want to pass a start date and end date to a stored procedure. What I would like to do is be able to click on any day of the week (Im trying it with the calendar control right now, dont know if the date picker is what I want.. any advice there would be great)

Anyway, I want to be able to click on any day of the week and have vb send the start of the week as the startdate and the end of the week as the end date. I could just pass in a date and let sql do the work with datepart function, but Im trying to learn vb and how it works.. so I want to figure out how you would go about it in vb.

So.. what control do I want to use, MonthCalendar or DatePicker and how do you specify the range

thanks
shannon
 
The DateTimePicker would probably be best. No reason to have a MonthCalendar if youre not allowing them to select ranges of dates.

Heres the overview of the DateTime object;
http://msdn.microsoft.com/library/d...pref/html/frlrfsystemdatetimememberstopic.asp

As you notice it can return a DayOfWeek enumerator;
http://msdn.microsoft.com/library/d...ml/frlrfsystemdatetimeclassdayofweektopic.asp

The question here is, what order are the enumerated days in? If the enumerator is like this;

public enum DayOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }

Then you could get the date for the first day of the week as such;

C#:
DateTime date = YourDateTimePicker.Value;

// Get the number of days between current day and beginning of week.
int numberOfDays = ((int) date.Value.DayOfWeek - (int) DayOfWeek.Sunday);

// Get the day of month for the start of the week.
int dayOfMonth = date.Value.Day - numberOfDays;

// Get the date for the start of the week.
DateTime startOfWeekDate = new DateTime(date.Year, date.Month, dayOfMonth);

This is just a general idea, dont be going off and copy/pasting this into your program. It probably needs a few tweeks.

You need to check the int values of the DayOfWeek enumerator, if theyre not from Sunday (0) to Saturday (6) then youll have to write your own enumerator that does follow that and write up a conversion method for converting DayOfWeek to your enumerator.

If you dont like the idea of enumerators then you could write up a lookup table for DayOfWeek. Come to think of it, a lookup table based off of DayOfWeek would probably be easier and more efficient then writing your own enumerator and a conversion method.
 
thanks for the info on datepicker... as far as the enumerator goes, looks like it works pretty much like sql... thanks for repling.
 
Back
Top