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

Input string converted to Date

3 Answers 144 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
JP13
Top achievements
Rank 1
JP13 asked on 05 Jun 2019, 05:14 PM
Is it possible to enter a string such as 10011989 and have it automatically changed to 10/01/1989?

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 10 Jun 2019, 10:51 AM
Hello,

It possible to have the DatePicker widget read the date without separators. You just need to specify the format that will be used in the parseFormats option. The definition in the .NET Core wrapper would look similar to this:


@(Html.Kendo().DatePicker()
      .Name("datepicker")
      .Format("mm/dd/yyyy")
      .ParseFormats(new string[] { "MMddyyyy" })
)


Give the configuration a try and let me know how it works for you.


Regards,
Viktor Tachev
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
JP13
Top achievements
Rank 1
answered on 10 Jun 2019, 01:47 PM

That works but causes another issue.

I have the following Javascript

function TermStartDateChange() {
  var jsTermStartDate = kendo.toString(this.value(), 'd');
  $('#iDOStartDate').data('kendoDatePicker').value(jsTermStartDate);
}

 

When I put the string '070119' into my control, it will adjust it 07/01/2019 correctly, but the other field gets a value of 01/01/2019. The debugger shows this.value as 'Tue Jan 01 2019 00:07:00 GMT-0500 (Eastern Standard Time)'.  Before I put the format and parseformats on my fields my script would correctly populate the new field. I also notice that if I enter 070119 into my control, and then click on the calendar icon to change the date, the dropdown shows the date as Jan 1 2019 as well.

 

What do I need to adjust to get the correct date in the new field as well as showing the entered date within the calendar?

0
Viktor Tachev
Telerik team
answered on 13 Jun 2019, 11:15 AM
Hello,

If you would like to parse a value as date from a specific format I would recommend taking advantage of the kendo.parseDate method and specifying the formats used for parsing explicitly. 

In case the behavior is not working as expected on your end please send us a dojo sample or a runnable project where the issue is replicated so we can examine it.


Regards,
Viktor Tachev
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
Date/Time Pickers
Asked by
JP13
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
JP13
Top achievements
Rank 1
Share this question
or