MonthYear picker

2 posts, 0 answers
  1. Trevor
    Trevor avatar
    3 posts
    Member since:
    Jul 2011

    Posted 13 Dec 2011 Link to this post

    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.

  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 13 Dec 2011 Link to this post

    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
Back to Top