I have a dropdown for selecting the year on my form, where the user will enter their date of birth.
My goal is to determine how many years I should display in the dropdown to ensure the person is at least 18 years old.
Currently, I am calculating this by subtracting 18 years from today's date, which brings me back to 1999. This way, I can confirm that the user is indeed 18 years or older.
getYears() {
var ageRestriction: number = 18;
var now = new Date();
var thisDate = (now.getFullYear() - 18);
// Now, I want to show the years before 1999 i.e 1998, 1997, 1996, 1995 etc
}
Next, I need to loop through and display 60 years prior to 1999:
1999, 1998, 1997, 1996, 1995, 1994 and so on
I'm struggling to figure out the syntax for achieving this, hence why I am asking this question.
If anyone can demonstrate how to accomplish this task or suggest a more efficient way of handling it, please feel free to share your knowledge with me :)