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

Problem with dd-MM-yyyy date format

3 Answers 920 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Zygmunt
Top achievements
Rank 1
Iron
Iron
Iron
Zygmunt asked on 28 Feb 2020, 01:11 PM

Hello

I have DateTimePicker with date in format dd-MM-yyyy. Initial date in this control is 01-02-2020. I want to write new date (31-01-2020) in MaskEdeditBox but after set day cursor correctly move to month section and day section changes walues to '01'. Could I define other behavior for this situations? For example when currently set month not has enough days month automatically decreases by 1.

 

Best wishes

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Mar 2020, 11:43 AM

Hello Zygmunt,

By design, RadDateTimePicker tries to handle the user's input while he is typing and it strives to keep a valid DateTime value. 31/02/2020 is not a valid DateTime and the user won't be allowed to enter it.

I would recommend you to use the MaskType.FreeFormDateTime which I believe is a suitable approach for your scenario. However, have in mind that while RadDateTimePicker is focused the user is allowed to enter the date in any format. But once the RadDateTimePicker control loses focus, the value will be parsed to a valid DateTime: https://docs.telerik.com/devtools/winforms/controls/editors/datetimepicker/free-form-date-time-parsing

Тhe format should be set in this way:

            this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
            this.radDateTimePicker1.Format = DateTimePickerFormat.Custom;
            this.radDateTimePicker1.CustomFormat = "dd-MM-yyyy";
I would like to clarify that this mask will add the - separators when the user presses the Enter or Tab keys or when the control lost the focus. Then the user input will be validated and separators will be added.

Please refer to the attached gif file that demos how the user enters 31032020.

Note that only the FreeFormDateTime mask will satisfy your request because other types validate on every key press and this behavior cannot be avoided.

 

Regards,
Peter
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Zygmunt
Top achievements
Rank 1
Iron
Iron
Iron
answered on 03 Mar 2020, 09:12 AM
Thank you for reply but it's not exactly what I want. I attach gif which show the behavior which I want to get.
0
Peter
Telerik team
answered on 04 Mar 2020, 01:37 PM

Hi Zygmunt,

We can offer only the FreeFormDateTime mask format (see the attached screenshot) for this case because other DateTime formats validate the date on every keypress and this behavior cannot be avoided.

Please, refer to the attached sample project.

Regards,
Peter
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Zygmunt
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Peter
Telerik team
Zygmunt
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or