No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    is there a util function that returns true If a string is a valid date while passing format like DD/MM/YYYY

    Framework
    2
    7
    1965
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      Fluksikarton last edited by Fluksikarton

      Hello guys, I’m using quasar and since quasar does not depend on moment.js is there a function that check if string is a valid date using a format of my own?

      For example
      cosnt myFormat = ''YYYY/MM/DD";
      isValidDate(‘1999/08/16’, myFormat); // should return true;

      1 Reply Last reply Reply Quote 0
      • rstoenescu
        rstoenescu Admin last edited by rstoenescu

        https://stackoverflow.com/questions/1353684/detecting-an-invalid-date-date-instance-in-javascript
        It’s quite easy so don’t think Quasar needs a util for this?

        F 2 Replies Last reply Reply Quote 0
        • F
          Fluksikarton @rstoenescu last edited by

          @rstoenescu I don’t see an answer in your link to my question. I’m passing string which is by default not a valid date is i parse it as date and the second param is the format

          1 Reply Last reply Reply Quote 0
          • rstoenescu
            rstoenescu Admin last edited by

            const d = new Date(‘16/08/1999’)
            if (Object.prototype.toString.call(d) === "[object Date]" && !isNaN(d.getTime())) {
               // it's valid
            }
            else {
               // it's not a valid date
            }
            

            You don’t need the format to be specified. The JS Date object is smart enough to detect the format and initialize the date correctly.

            1 Reply Last reply Reply Quote 0
            • rstoenescu
              rstoenescu Admin last edited by

              Btw: http://quasar-framework.org/components/handling-js-date.html#Validate

              F 1 Reply Last reply Reply Quote 0
              • F
                Fluksikarton @rstoenescu last edited by

                @rstoenescu Ok sorry updated my question

                1 Reply Last reply Reply Quote 0
                • F
                  Fluksikarton @rstoenescu last edited by

                  @rstoenescu I’m actually using isValid, but this function can’t validate YYYY/MM/DD

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post