This is a migrated thread and some comments may be shown as answers.
MonthYear picker
1 Answer 40 Views
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 13 Dec 2011, 08:54 AM
I want to replace my RadDatePicker with a RadMonthYearPicker resulting in less clutter for the page, problem is I need to get the start and end of the month selected via MonthYear picker for my query.

the statement below:
protected void DateChange(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
        {
            //Session.Add("StartDate", RadDatePicker1.SelectedDate);
            Session.Add("selectedMonth", RadMonthYearPicker1.DbSelectedDate);
        }

returns merely the month I choose, the day today, and the chosen year. ex return '5/13/2011'.  When I want to get '5/1/2011' and '5/31/2011'
Any suggestions on how I can get the 'start' and 'end' of the month or do I stick with RadDatePicker for now? If there is a way to do this pointing me in the right direction would be much appreciated.

Thanks

1 Answer, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 13 Dec 2011, 02:46 PM
Hello Trevor,

That is pretty much how the RadMonthYearPicker works. It only returns one date, not two. If you want to get the two dates, you'll need to generate them off the SelectedDate of the RadMonthYearPicker. So something like this:

DateTime selectedDate = RadMonthYearPicker.SelectedDate.Value;
DateTime startDate = selectedDate.AddDays((selectedDate.Day - 1) * -1);
DateTime endDate = startDate.AddDays(DateTime.DaysInMonth(startDate.Year, startDate.Month) - 1);

I hope that helps
Asked by
Trevor
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Share this question
or