This is a migrated thread and some comments may be shown as answers.

Weeknumbers in DatePicker

1 Answer 365 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Veteran
Maurice asked on 30 Jun 2020, 06:46 AM

Is it possible to show the weeknumbers in a DatePicker?

We work most of the time with weeknumbers instead of a date so people know they have to select e.g. the monday of week 27 instead of 29-06-2020

 

Thanks,

 

Maurice

1 Answer, 1 is accepted

Sort by
0
Svetoslav Dimitrov
Telerik team
answered on 30 Jun 2020, 07:38 AM

Hello Maurice,

I have opened a Feature Request on our Feedback Portal regarding adding a week number column in the DatePicker, like this example, you can see it here. I have given a Vote on your behalf and you can Follow it for email notifications. 

To get the week of the year you could use either the ValueChanged or OnChange events for the DatePicker and pass that DateTime object to a custom method that returns the week number. I have created a code sample, below, where I use the OnChange event for the DatePicker and display the week.

@using System.Globalization;

<TelerikDatePicker @bind-Value="datePickerValue" OnChange="@MyChangeHandler" />

<br>

<div>
    The selected date @datePickerValue.ToShortDateString() is in @weekOfYear week of the year.
</div>

@code  {
    DateTime datePickerValue { get; set; } = DateTime.Now;

    int weekOfYear { get; set; }

    void MyChangeHandler(object input)
    {
        DateTime userInput = (DateTime)input;
        weekOfYear = GetWeekOfYear(userInput);
    }

    int GetWeekOfYear(DateTime date)
    {
        CultureInfo culture = new CultureInfo("en-US");
        Calendar cal = culture.Calendar;

        CalendarWeekRule weekRule = culture.DateTimeFormat.CalendarWeekRule;
        DayOfWeek firstDayOfWeek = culture.DateTimeFormat.FirstDayOfWeek;

        return cal.GetWeekOfYear(date, weekRule, firstDayOfWeek);
    }
}

 

Regards,
Svetoslav Dimitrov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
DatePicker
Asked by
Maurice
Top achievements
Rank 1
Veteran
Answers by
Svetoslav Dimitrov
Telerik team
Share this question
or