I know there a lots same questions, but none of them work as I need, about to disable future YYYY-MM-DD in React Native Date Picker:
<DatePicker
modal
open={open}
date={date}
mode="date"
onConfirm={updateFilter}
maximumDate={new Date()}
onCancel={() => {
setOpen(false)
}}
/>
But it doesn’t work, the future month and date still displayed, only future year is disabled. How to disable all of them?
3
Answers
According to the Readme on the repo for
react-native-date-picker
, themaximumDate
prop requires a string in the form YYYY-MM-DD. Therefore you should instantiate a new Date object and store it in a variable on which you can call the various methods you need to access those portions of the Date. Then you can pass that prop a new Date object, and add the pieces of the string you need, like so:Main DatePicker component:
Call the DatePicker component:
Version i used here: