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

The field must be a date error when using date format as MM/yyyy

1 Answer 1358 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Rajeev
Top achievements
Rank 1
Rajeev asked on 05 Sep 2016, 12:00 PM

Using below code to render date as month picker.

@(Html.Kendo().DatePickerFor(d => d.StartDate).Format("MM/yyyy") 
            .ParseFormats(new String[] {"MM/yyyy" }))

But the validation error showing "The field Start Date must be a date.".  The property  StartDate is DateTime nullable  field.

 

I have to use a month picker in my page.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 07 Sep 2016, 07:37 AM
Hi Rajeev,

Such format is not supported and the validation of the field will fail. This is due to the fact that month and year alone could not be used for creating a Date object. You can easily test this in the browser's console by parsing a string to a Date object with only the month and the year:
Date.parse("09/2016")

As you will notice, the above will not create a Date object. The same apples to the field validation. If you need to select only a month, you might consider using a simple DropDownList with the months.


Regards,
Konstantin Dikov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Date/Time Pickers
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or