xgfe / react-native-datepicker

react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS
MIT License
2.12k stars 726 forks source link

How to set init year of date picker #367

Open manhthepixta opened 4 years ago

manhthepixta commented 4 years ago

Let say today is Sep 25, 2019 I want to set the init year to 2000 for example. Then when I open the date picker, it show as attached image. Please suggest. Thanks.

image

Mohammad-Khalid23 commented 4 years ago
you can set date={new Date('2000-10-20')} as your initial date on picker, you can set it on state
 `<DatePicker
       style={{width: 200}}
     //date={new Date('2000-10-20')}
    date={this.state.date} // here you can set your inital date that will show when picker open
    mode="date"
    placeholder="select date"
    format="YYYY-MM-DD"
    minDate="2016-05-01"
    maxDate="2016-06-01"
    confirmBtnText="Confirm"
    cancelBtnText="Cancel"
    customStyles={{
      dateIcon: {
        position: 'absolute',
        left: 0,
        top: 4,
        marginLeft: 0
      },
      dateInput: {
        marginLeft: 36
      }
      // ... You can check the source to find the other keys.
    }}
    onDateChange={(date) => {this.setState({date: date})}}
  />`