RadDatePicker date input culture / parsing issue when using DateInput-DateFormat

1 Answer 193 Views
DateInput DatePicker
Greg
Top achievements
Rank 1
Greg asked on 27 Jul 2021, 08:16 PM

I am having an issue with RadDatePicker when trying to set the input date format to yyyyMMdd.  The desired outcome is allow the user to enter a date in yyyyMMdd format but display the date in the culture specific short date format.  I can achieve the desired functionality like this:


<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Test Page</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
            <telerik:RadDatePicker runat="server" ID="RadDatePicker1" 
                RenderMode="Lightweight" Culture="English (United States)" 
                DateInput-DisplayDateFormat="d" DateInput-DateFormat="yyyyMMdd" >
            </telerik:RadDatePicker>
        </form>
    </body>
</html>

 

The issue is when using the en-US culture.  I can select a date from the popup and the date is displayed in MM/dd/yyyy format in the textbox.  When I click in the textbox to enter the date, it is automatically changed to yyyyMMdd format and updating it in that format way works correctly.  However, if I enter a date in MM/dd/yyyy format, the date is parsed in the dd/MM/YYYY format so 7/6/2021 becomes 6/7/2021.

When using the fr-FR culture, for example, it correctly parses entered dates entered as either yyyyMMdd or dd/MM/YYYY.

We are using Telerik UI for ASP.NET AJAX 2021.2.616

Any help would be greatly appreciated.

Greg

1 Answer, 1 is accepted

Sort by
1
Attila Antal
Telerik team
answered on 30 Jul 2021, 10:32 AM

Hi Greg,

The Input DateFormat is there to tell the RadDatePicker how to intercept the values. If the format says Year First, then Month, then Day, you need to provide the values in the same exact order: YearMonthDay.

If a user comes and types 1/12/2021, how would you know, which is the month and which is the day? It's almost impossible to guess unless the user uses values such as 31/1/2021. Then you know, that 31 cannot be a Month, so it will be interpreted as the Day, the value 1 as the Month, and 2021 the year.

Here are two example scenarios that you may never guess, not even by the region, or computer locale.

  • Scenario 1: User inputs French format on a Machine set to English culture.
  • Scenario 2: User inputs English format on a Machine set to French culture.

Regards,
Attila Antal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Greg
Top achievements
Rank 1
commented on 30 Jul 2021, 11:31 AM

Attila,

I see what you are saying but in this case neither of your scenarios are in play. When I set the culture to us-EN and enter the date in the us-EN format, it parsed it as if the culture was set to fr-FR. According to this document, it should be parsed in the order of the culture's format:
https://docs.telerik.com/devtools/aspnet-ajax/controls/dateinput/features/parsing-dates
"a month/day/year triplet: a month can be both a numeric value or a month name. The order of the parts in the triplet is culture specific."
Regards,
Greg
Attila Antal
Telerik team
commented on 30 Jul 2021, 11:55 AM

"According to this document, it should be parsed in the order of the culture's format:"

This is only correct unless you have changed the default DateInput format like in: DateInput-DateFormat="yyyyMMdd".

This format is the reason you must input the numbers in the following order: YearMonthDay (e.g. July 6th, 2021 as 20210706). If you were to input the English US format 07062021 the Calendar would not accept it.

Greg
Top achievements
Rank 1
commented on 30 Jul 2021, 12:10 PM

What you are saying does agree with my observations. However, the DateInput does accept many variations beyond the explicitly given format. I can type April 10, for example, and it gets parsed as 20210410. As a matter of fact, it appears that every parsing example in the document works as stated with an explicit DateFormat except for the month/day/year triplet. The culture did not impact the order of culture's format.

I do appreciate your responding to this question. Perhaps I should enter a feedback post to add some clarification in the document or see if the parser could be changed. What are your thoughts, please?
Best regards,
Greg
Attila Antal
Telerik team
commented on 30 Jul 2021, 02:07 PM

Greg,

I think it would be best if you could submit a feedback on this. Try to list all the scenarios you would like an answer for, and point out that part of the docs that is confusing. We will try to explain everything and make that transparent for everyone to understand.

Greg
Top achievements
Rank 1
commented on 30 Jul 2021, 02:31 PM

Attila,

Thank you for your time answering my questions. I will do that.

Greg
Attila Antal
Telerik team
commented on 05 Aug 2021, 09:43 AM

Greg,

I am also sharing the link to the Bug report here, so everyone can find it easily: RadDatePicker date parsing issue when using both DateInput-DisplayDateFormat and DateInput-DateFormat

Tags
DateInput DatePicker
Asked by
Greg
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or