Declined
Last Updated: 02 May 2025 07:25 by ADMIN
AMF
Created on: 28 Apr 2025 09:27
Category: DatePicker
Type: Feature Request
1
Auto fill year when entering two digits in four digit format date

We would like to get the datetime picker to autofill the year when entering just two digits for the year with a format of dd-MM-yyyy HH:mm:ss.

So when you enter 23-04-25 it changes to 23-04-2025. Currently it changes it to 23-04-0025, which isn't our desired result.

Something along the lines of how this works: https://jsfiddle.net/anbdwL0h/ but then with a 4 year digit format as result.

1 comment
ADMIN
Hristian Stefanov
Posted on: 02 May 2025 07:25

Hello,

We discussed this internally with our development team, and as a result, I'm marking this item as declined. The reason is that such functionality would be very difficult to support as a built-in feature. There are too many assumptions the component would need to make internally, which may not cover all possible use cases reliably. Instead, our intention is for users to enter two-digit years using the appropriate double-digit format defined in the component's settings.

However, I still found a way to achieve the behavior you're after using the existing capabilities of the DateTimePicker. You can handle the ValueChanged event and adjust the year when you detect a two-digit input. Here's a sample implementation to get you started:

<TelerikDateTimePicker Value="@selectedTime"
                       ValueChanged="@( (DateTime? d) => MyValueChangeHandler(d) )"
                       Format="dd-MM-yyyy HH:mm:ss" 
                       Min="@Min"
                       Width="250px">
</TelerikDateTimePicker>

@code {
    private DateTime? selectedTime = DateTime.Now;
    public DateTime Min = new DateTime(0001, 1, 1, 1, 1, 0);

    private void MyValueChangeHandler(DateTime? userInput)
    {
        if (userInput.HasValue)
        {
            var inputDate = userInput.Value;
            if (inputDate.Year < 100) // assume two-digit year
            {
                var correctedDate = new DateTime(2000 + inputDate.Year, inputDate.Month, inputDate.Day,
                                                 inputDate.Hour, inputDate.Minute, inputDate.Second);
                selectedTime = correctedDate;
            }
            else
            {
                selectedTime = inputDate;
            }
        }
        else
        {
            selectedTime = null;
        }
    }
}

Regards,
Hristian Stefanov
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.