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

2 posts, 0 answers
  1. Rajeev
    Rajeev avatar
    8 posts
    Member since:
    Jan 2015

    Posted 05 Sep 2016 Link to this post

    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.

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2087 posts

    Posted 07 Sep 2016 Link to this post

    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:

    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.

    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
Back to Top