Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Get selected date from ReactNative-DatePickerAndroid

I am following ReactNative DatePickerAndroid Docs. For DatePickerIOS we have onDateChange method.

Is there any similar method to get selected date from DatePickerAndroid? Above documentation didn't mention any code example to get selected date.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can get selected date in showPicker method from given code example :

showPicker = async (stateKey, options) => {
    try {
      var newState = {};
      const {action, year, month, day} = await DatePickerAndroid.open(options);
      if (action === DatePickerAndroid.dismissedAction) {
        newState[stateKey + 'Text'] = 'dismissed';
      } else {
        // <<<< Newly selected date >>>>
        var date = new Date(year, month, day);
        newState[stateKey + 'Text'] = date.toLocaleDateString();
        newState[stateKey + 'Date'] = date;
      }
      this.setState(newState);
    } catch ({code, message}) {
      console.warn(`Error in example '${stateKey}': `, message);
    }
  };
render() {
   return (
   <TouchableWithoutFeedback
    onPress={this.showPicker.bind(this, 'spinner', { date: this.state.presetDate })}>
     <View>
        <Text style={styles.text}>Date selector</Text>
     </View>
   </TouchableWithoutFeedback>
  )
}
over 4 years ago · Santiago Trujillo Report

0

As we can see the example code on documentation, create an async function, this function will handle promise data, and trigger this function to you component Text with onPress function or TexInput with onFocus function. example:

async _onMyDatePress(){
   try {
            const {action, year, month, day} = await DatePickerAndroid.open({           
                date: new Date()
            });

            if(action == DatePickerAndroid.dateSetAction){
                console.log(year + ' ' + month + ' ' + day);
            }

        } catch ({code, message}) {
            console.warn('Cannot open date picker', message);
        }   
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!