-1

I have a date picker, i want to user cannot pick a date but date now minus this date less than 18 year(i don't want the user less than 18 years old).but i don't know how to do that.

i described my idea by this code below.

    const nowDate = new Date()
    const valueCondition = 18
    const dateWishes = nowDate - valueCondition

how can i do that?

have a nice day, everyone!

1 Answers1

1

Use getFullYear()

const nowDate = new Date();
const valueCondition = 18;
const dateWishes = nowDate.getFullYear() - valueCondition; // 2021 - 18
console.log(dateWishes); // 2003
ar099968
  • 6,963
  • 12
  • 64
  • 127
  • 2
    This method will exclude a great many dates that are between 17 and 18 years ago. – RobG Nov 26 '21 at 07:58