Datepicker enhancement: add option for expected input formats #606

Closed
opened 2026-01-29 17:40:09 +00:00 by claunia · 3 comments
Owner

Originally created by @jonheslop on GitHub (Oct 27, 2022).

Hello,

We use the datepicker like this:

<RadzenDatePicker 
    TValue="DateTime?" 
    Value="@_boundValue"
    DateFormat="dd MMM yyyy"
    Kind="DateTimeKind.Local"
    Change=HandleDatePickerChangeAsync
    DateRender="HandleDateRender"/>

We display the date in the input field with dd MMM yyyy as it is more unambigous for Europeans and Americans.

However we have noticed some users, who choose to forego the picker and type the date will use the more familar 03/04/2023 format. We are based in the UK and people expect 03/04/2023 to equal 03 April 2023, however Radzen parses that as 04 March 2023

I can see this happens here, the dd/MM/yyyy format doesnt match dd MMM yyyy so it falls back to the default method:

b5f414623e/Radzen.Blazor/RadzenDatePicker.razor.cs (L515-L521)

So the approach could be for the line 520 parse to use local standards (I thought Kind="DateTimeKind.Local" might do that)

But perhaps another solution could be an InputFormat param where you could list formats to try and parse with before falling back to the default on line 520

so something like: InputFormat="dd MMM yyyy, dd/MM/yyyy"

Originally created by @jonheslop on GitHub (Oct 27, 2022). Hello, We use the datepicker like this: ``` <RadzenDatePicker TValue="DateTime?" Value="@_boundValue" DateFormat="dd MMM yyyy" Kind="DateTimeKind.Local" Change=HandleDatePickerChangeAsync DateRender="HandleDateRender"/> ``` We display the date in the input field with `dd MMM yyyy` as it is more unambigous for Europeans and Americans. However we have noticed some users, who choose to forego the picker and type the date will use the more familar `03/04/2023` format. We are based in the UK and people expect `03/04/2023` to equal `03 April 2023`, however Radzen parses that as `04 March 2023` I can see this happens here, the `dd/MM/yyyy` format doesnt match `dd MMM yyyy` so it falls back to the default method: https://github.com/radzenhq/radzen-blazor/blob/b5f414623e695d72de6fd79f21537d84aa5c7e2c/Radzen.Blazor/RadzenDatePicker.razor.cs#L515-L521 So the approach could be for the line 520 parse to use local standards (I thought `Kind="DateTimeKind.Local"` might do that) But perhaps another solution could be an `InputFormat` param where you could list formats to try and parse with before falling back to the default on line 520 so something like: `InputFormat="dd MMM yyyy, dd/MM/yyyy"`
claunia added the good first issue label 2026-01-29 17:40:09 +00:00
Author
Owner

@akorchev commented on GitHub (Nov 12, 2022):

We would probably add a new Parse method that users can implement as they need. Pull requests welcome!

@akorchev commented on GitHub (Nov 12, 2022): We would probably add a new Parse method that users can implement as they need. Pull requests welcome!
Author
Owner

@exrezzo commented on GitHub (Feb 26, 2023):

Does this issue still happen?

@exrezzo commented on GitHub (Feb 26, 2023): Does this issue still happen?
Author
Owner

@xs4free commented on GitHub (Jul 25, 2023):

@jonheslop at the company I currently work for we ran into a similar problem and we were thinking in the same direction as your request.

After reading @akorchev comment about a new parse-method, I implemented the change and made my first PR #1090 for this project. Hope this gets approved so we can both benefit.

ps. An example of the function we want to use to parse the date-input is:

        public static DateTime? ParseDate(string input)
        {
            string[] formats = { "dd-MM-yyyy", "dd/MM/yyyy", "dd-MM-yy", "dd/MM/yy", "ddMMyyyy", "ddMMyy", "dd-MM", "dd/MM", "ddMM" };

            foreach(var format in formats)
            {
                if (DateTime.TryParseExact(input, format, null, System.Globalization.DateTimeStyles.None, out var result))
                {
                    return result;
                }
            }

            return null;
        }

@xs4free commented on GitHub (Jul 25, 2023): @jonheslop at the company I currently work for we ran into a similar problem and we were thinking in the same direction as your request. After reading @akorchev comment about a new parse-method, I implemented the change and made my first PR #1090 for this project. Hope this gets approved so we can both benefit. ps. An example of the function we want to use to parse the date-input is: ```csharp public static DateTime? ParseDate(string input) { string[] formats = { "dd-MM-yyyy", "dd/MM/yyyy", "dd-MM-yy", "dd/MM/yy", "ddMMyyyy", "ddMMyy", "dd-MM", "dd/MM", "ddMM" }; foreach(var format in formats) { if (DateTime.TryParseExact(input, format, null, System.Globalization.DateTimeStyles.None, out var result)) { return result; } } return null; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#606