0

In my VueJS application I'm using momentjs to validate if the user selected date is today or a future date.

Following is my custom validation rule.

const dateIsToday = (value) => {
    let todayDate = moment();
    let selectedDate = moment(value, "DD-MM-YYYY");
    return moment(selectedDate).isSameOrAfter(todayDate);
};

This rule works with older dates.

But even when user selects a today's date, it gives an error.

Instead I should be able to allow to select today's date.

Volka Dimitrev
  • 337
  • 4
  • 15
  • 38
  • can you also provide the date for which the error is happening? It will be helpful to answer your problem – Arun AK Apr 17 '22 at 04:38
  • "it gives an error" - what error? – Estus Flask Apr 17 '22 at 06:47
  • @EstusFlask it show's the validation message for the current date as well – Volka Dimitrev Apr 18 '22 at 03:09
  • You are not getting the expected result because momentjs takes into account full date + time when comparing, as it's explained in the [docs](https://momentjs.com/docs/#/query/is-same-or-after/) and in several SO answers. You can simply add an extra parameter to limit granularity. – VincenzoC Apr 19 '22 at 07:41

0 Answers0