Parsing dates

4 posts, 0 answers
  1. Michael Hurse
    Michael Hurse avatar
    19 posts
    Member since:
    Jun 2008

    Posted 04 Apr Link to this post

    Hi,

    I am trying to get the MVC date picker to parse and format dates the same as the ASP.Net date picker does, eg. user enters 1/1/11 and the picker formats it into 1/1/2011.

    How do I get the MVC date picker to do this?

    Thanks.

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 05 Apr Link to this post

    Hello Michael,

    In order to specify how the dates are parsed you can configure the parseFormats setting of the picker widget.

    Check out the following example that illustrates the approach:



    Regards,
    Viktor Tachev
    Telerik
    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Michael Hurse
    Michael Hurse avatar
    19 posts
    Member since:
    Jun 2008

    Posted 05 Apr in reply to Viktor Tachev Link to this post

    Thanks Viktor,

    I was hoping for something better that that as the ASP.Net controls just do it for you. Are there any quirks around the ordering of the date formats or is any order ok?

     

     

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 06 Apr Link to this post

    Hi Michael,

    You can set the format and parseFormats based on your requirements. One thing to note is that when you set multiple parseFormats the widget will use the first format that can be applied to the value entered by the user. Thus, you should be careful not to use parse formats that can be ambiguous.

    For example, lets assume that you have the following setting:

    parseFormats: ["MM/dd/yy", "dd/MM/yy"]

    If the user enters February 1-st, 2003 like this 

    1/2/3

    the date will be parsed as January 2-nd. This is because the widget cannot guess the date and will use the first parse format.

    On the other hand if the input is the following:

    15/1/3

    The date will be parsed as January 15-th - the first parse format cannot be applied and the widget tries the second one.


    Regards,
    Viktor Tachev
    Telerik
    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
UI for ASP.NET MVC is VS 2017 Ready