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

127
Views
Geeting value differance in MUI date picker

I am using Mui 5 date picker my issue is if I change the date using calendar I will get the expected result like the example I selected 26 I get this "2022-01-26T09:16:10.000Z" but when I edit directly in the field example I selected 27 I get this "2022-01-26T18:30:00.000Z" because of this I will get a validation error I am not understanding why this happening and after the edit, if the select date from again calendar 26 then the final value is "2022-01-25T18:30:00.000Z" for external I am using momentjs and fromik.

  const [value, setValue] = React.useState(null);

  return (
    <Box>
    {JSON.stringify(value)}
    <LocalizationProvider dateAdapter={AdapterDateFns}>
    
      <DatePicker
        label="Basic example"
        value={value}
        onChange={(newValue) => {
          setValue(newValue);
        }}
        renderInput={(params) => <TextField {...params} />}
      />
    </LocalizationProvider>
    </Box>
  );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Using moment, set the initial value to start of the day startOf.

const [value, setValue] = React.useState(moment().startOf('day'))

Code snippet:

export default function BasicDatePicker() {
  const [value, setValue] = React.useState(moment().startOf('day'));
  
  return (
    <LocalizationProvider dateAdapter={AdapterMoment} >
      <DatePicker
        label="Basic example"
        value={value}
        onChange={(newValue) => {
          setValue(moment(newValue));
        }}
        renderInput={(params) => <TextField {...params} />}
      />
    </LocalizationProvider>
  );
}

Sandbox : here

EDIT: if you have a specific date to be passed, React.useState(moment('03-03-2021').startOf("day"))

about 4 years ago · Juan Pablo Isaza 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!