Chaudhry Talha
Chaudhry Talha

Reputation: 7868

TypeError: props.date.getTime is not a function. (In 'props.date.getTime()', 'props.date.getTime' is undefined)

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)

enter image description here

Upvotes: 0

Views: 1753

Answers (3)

Nikhil bhatia
Nikhil bhatia

Reputation: 1397

try like this

{!!userUserDOB?.getTime && <DatePicker
                            style={styles.dobPicker}
                            date={userUserDOB}
                            onDateChange={setUserDOB}
                            mode={'date'}
                            textColor={colors.darkBlue}
                        />}

Upvotes: 0

Gourav Goel
Gourav Goel

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

Ch Umair
Ch Umair

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

Related Questions