|
| 1 | +--- |
| 2 | +title: How to Change the Default Starting Day of the Week |
| 3 | +description: Learn how to set a first day of the week that's different from the default one in the Telerik Blazor DatePicker component by modifying the current culture settings. |
| 4 | +type: how-to |
| 5 | +page_title: How to Change the Default Starting Day of the Week |
| 6 | +slug: datepicker-kb-change-starting-day-of-week |
| 7 | +tags: datepicker, blazor, cultureinfo, firstdayofweek |
| 8 | +res_type: kb |
| 9 | +ticketid: 1665695 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | +<table> |
| 14 | + <tbody> |
| 15 | + <tr> |
| 16 | + <td>Product</td> |
| 17 | + <td>DatePicker for Blazor, Calendar for Blazor</td> |
| 18 | + </tr> |
| 19 | + </tbody> |
| 20 | +</table> |
| 21 | + |
| 22 | +## Description |
| 23 | + |
| 24 | +This KB article answers the following questions: |
| 25 | +* How can I change the first day of the week in the DatePicker? |
| 26 | +* Is it possible to set a different day as the start of the week from the default one in the Telerik DatePicker for Blazor? |
| 27 | +* What steps should I follow to modify the start of the week in a DatePicker component? |
| 28 | + |
| 29 | +## Solution |
| 30 | + |
| 31 | +To set the start of the week to a different one in the Telerik DatePicker for Blazor, override the `FirstDayOfWeek` property of the current culture in your application. Follow the steps below to implement this solution: |
| 32 | + |
| 33 | +1. Include the necessary namespaces for [globalization]({%slug globalization-formats%}) in your component. |
| 34 | +2. Add the Telerik DatePicker component to your razor page. |
| 35 | +3. Override the `OnInitialized` method to change the current culture's `FirstDayOfWeek` to the desired one. |
| 36 | + |
| 37 | +````CSHTML |
| 38 | +
|
| 39 | +@using System.Globalization |
| 40 | +
|
| 41 | +<TelerikDatePicker @bind-Value="@Date"/> |
| 42 | +
|
| 43 | +@code { |
| 44 | + private DateTime Date { get; set; } = DateTime.Now; |
| 45 | +
|
| 46 | + protected override void OnInitialized() |
| 47 | + { |
| 48 | + var cultureInfo = new CultureInfo("en-US"); |
| 49 | + cultureInfo.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday; |
| 50 | + CultureInfo.DefaultThreadCurrentCulture = cultureInfo; |
| 51 | + CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; |
| 52 | + } |
| 53 | +} |
| 54 | +```` |
| 55 | + |
| 56 | +By setting the `FirstDayOfWeek` property to `DayOfWeek.Monday`, the DatePicker will start the week with Monday based on the modified culture settings. |
| 57 | + |
| 58 | +## See Also |
| 59 | + |
| 60 | +- [DatePicker Overview Documentation]({%slug components/datepicker/overview%}) |
0 commit comments