Reputation: 7868
I'm using react-native-date-picker to show the date picker. Here is how I'm doing it:
...
const [userUserDOB, setUserDOB] = useState(new Date());
...
<DatePicker
style={styles.dobPicker}
date={userUserDOB}
onDateChange={setUserDOB}
mode={'date'}
textColor={colors.darkBlue}
/>
...
dobPicker: {
alignSelf: 'center'
},
This should show date picker but instead as soon as the screen loads I get this error:
TypeError: props.date.getTime is not a function. (In 'props.date.getTime()', 'props.date.getTime' is undefined)
Upvotes: 0
Views: 1753
Reputation: 1397
try like this
{!!userUserDOB?.getTime && <DatePicker
style={styles.dobPicker}
date={userUserDOB}
onDateChange={setUserDOB}
mode={'date'}
textColor={colors.darkBlue}
/>}
Upvotes: 0
Reputation: 83
This works for me, check this and let me know
setDOB = (event, d) => {
let a= d..getTime()
console.log(a);
this.setState({DOB:a})
}
< DateTimePicker
testID="dateTimePicker"
value={new Date(2015, 0, 1)}
mode="date"
cancelBtnText="Cancel"
customStyles={{
format="YYYY-MM-DD"
maximumDate= {new Date(2015, 0, 1)}
minimumDate={new Date(1950, 0, 1)}
is24Hour={true}
display="default"
onChange={this.setDOB}
/>
Upvotes: 2
Reputation: 21
firstly check the date in prop and then pass it from new Date()
as
new Date( props.date ).getTime()
this will work for you i.a
Upvotes: 0