0

I am using react js for my form. currently i am loading my date to the text box. but currently its show with different format please check this

     <Form.Control
            type="text" disabled
            size="sm"
            placeholder=""
            name="termDate"
            onChange={handleChange}
            value={values.termDate}
          />

I am setting the value using the code given below:

setFieldValue('termDate', dataObj.termDate);

when I use the above code, textbox date load as below. enter image description here

I need to load this date as 2021-07-07.

How do I format this before loading it to the textbox?

2
  • 1
    setFieldValue('termDate', dataObj.termDate.split('T')[0]); I do this but might not be the optimal way Commented Jul 7, 2021 at 10:04
  • dataObj.termDate.substr(0, 10) Commented Jul 7, 2021 at 10:04

1 Answer 1

1

Use momentjs. This oneliner will help

moment(dataObj.termDate).format("YYYY-MM-DD");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.