reactjsreact-day-picker

React day picker return all data when expecting only day


So I'm using react-day-picker, for calendar.

import DayPickerInput from 'react-day-picker/DayPickerInput';
import 'react-day-picker/lib/style.css';

This is the function I use :

<DayPickerInput  onDayChange={day => this.onEduGraduateFromChange(d, day)}  />

The thing is function day=> return lot of thing like:

Wed Aug 07 2019 12:00:00 GMT+0100 (British Time)

when this is the expected format: 2019-08-07

How can I get this?

My function send data over the app, so I don't need all that stuff like time etc.. just day/month/year it is possible?

How can I get the expected format?

I try day instead of date but without effort.

onDayChange={date => this.onEduGraduateFromChange(d, date)}

I use console.log to output the whole json data and I got

graduateFrom: 'Wed Aug 07 2019 12:00:00 GMT+0100 (British Time)'

I expected the output day/month/year, but the actual output is

Wed Aug 07 2019 12:00:00 GMT+0100 (British Time)

Solution

  • refer this docs for more insights

    In onDayChange you can do this=>

    import dateFnsFormat from 'date-fns/format';
    let date = dateFnsFormat(day,'DD/MM/YYYY');
    console.log(date)