is there a util function that returns true If a string is a valid date while passing format like DD/MM/YYYY
-
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; -
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? -
@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
-
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.
-
-
@rstoenescu Ok sorry updated my question
-
@rstoenescu I’m actually using isValid, but this function can’t validate YYYY/MM/DD