Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restrict years in calendar #231

Open
joelyeye opened this issue Feb 19, 2020 · 1 comment
Open

restrict years in calendar #231

joelyeye opened this issue Feb 19, 2020 · 1 comment

Comments

@joelyeye
Copy link

Is there a way to restrict the calendar to only go back to n amount of years? I am having an issue that when a user enters lets say 10/15/19 it pick 10/15/0019 instead if 10/15/2019.

Thanks

@kesalkarsaket
Copy link

@joelyeye you can use react-datepicker library to only go back to restricted amount of years. You can try out using react moment library and u can pass props like min and max dates to restrict the year limit
<DatePicker
open={dateOpen}
minDate={moment().subtract(18, 'years').toDate()}
maxDate={moment().toDate()}
mode="date"
onConfirm={date => {
let mm = date.getMonth() + 1;
let dd = date.getDate();
const yy = date.getFullYear();
if (dd.toString().length === 1) dd = 0${dd};
if (mm.toString().length === 1) mm = 0${mm};
const selectedDate = ${dd}/${mm}/${yy};
setDateOpen(false);
}}
onCancel={() => {
setDateOpen(false);
}}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants