DisplayDateStart & DisplayDateEnd

5 posts, 0 answers
  1. paul
    paul avatar
    16 posts
    Member since:
    Jan 2011

    Posted 09 Jan 2012 Link to this post

    Hi Telerik,

    I was hoping that these two properties (DisplayDateStart and DisplayDateEnd) would give me the date range that is visible on the calendar but in my case they are both empty.

    Is this a bug?
  2. Todor
    Admin
    Todor avatar
    778 posts

    Posted 10 Jan 2012 Link to this post

    Hello Paul,

    Thank you for writing.
    This is the expected behavior for these properties. They should be used to specify a range for the dates that the user can view. On the other hand, the properties SelectableDateStart and SelectableDateEnd specify the dates that the user can select.
    If, however, you want the dates that are visible currently in the calendar, you can use the property DisplayDate. It is of type DateTime and would give you the first date of the month that is currently visible on the calendar.

    Kind regards,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. paul
    paul avatar
    16 posts
    Member since:
    Jan 2011

    Posted 10 Jan 2012 Link to this post

    Hi Todor

    I am aware of display date giving me the first date of the month but it doesn't tell me the full range of dates displayed on the calendar.

    For example, if i look at Feb 2012 i see the dates 29/01 to 10/03 - these are the dates i need to access.
  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 10 Jan 2012 Link to this post

    Hi Paul,

    RadCalendar currently does not expose properties which provide the dates that you need to display in your scenario. However, you can write some code and find those dates. Here is one way to do it:

    const int TotalNumberOfDaysInCalendar = 42;
     
    DayOfWeek? firstDayOfWeek = this.radCalendar.FirstDayOfWeek;
    if (firstDayOfWeek == null)
    {
        if (radCalendar.Culture != null)
        {
            firstDayOfWeek = this.radCalendar.Culture.DateTimeFormat.FirstDayOfWeek;
        }
        else
        {
            firstDayOfWeek = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
        }
    }
     
    DateTime firstDayInMonth = new DateTime(this.radCalendar.DisplayDate.Year, this.radCalendar.DisplayDate.Month, 1);
     
    int daysToSubtract = (int)firstDayInMonth.DayOfWeek - (int)firstDayOfWeek;
    if (daysToSubtract < 0)
    {
        daysToSubtract += 7;
    }
     
    DateTime firstDayToDisplay = firstDayInMonth.AddDays(-daysToSubtract);
    DateTime lastDayToDisplay = firstDayToDisplay.AddDays(TotalNumberOfDaysInCalendar - 1);

    I hope this helps. If you need more assistance, don't hesitate to write us again.

    Kind regards,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. paul
    paul avatar
    16 posts
    Member since:
    Jan 2011

    Posted 10 Jan 2012 Link to this post

    Perfect - Thank you
Back to Top
DevCraft banner