I am currently using Mui Datepicker library from @mui/x-date-pickers/DatePicker
.
Here's my sample code
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DatePicker
inputFormat="MM/dd/yy"
value={date}
minDate={new Date()}
disablePast
onChange={(newValue) => {
console.log("new value", newValue)
setDate(newValue);
}}
renderInput={(props) => (
<TextField
autoFocus
size="small"
{...props}
inputProps={{
...props.inputProps,
autocomplete: 'off',
placeholder: 'MM/DD/YY',
}}
/>
)}
/>
</LocalizationProvider>
Now, I would like to use MM/dd/yy
as the date format. But when I type in 10/30/99, it returns a date 10/30/1999. I would like it to return 10/30/2099.
It is happening because the library is trying to predict the nearest year to 99 from the current date (reference date).
Is there a way to ensure I only get future dates. So in this case it returns the year 2099 instead of 1999.
I tried setting minDate={new Date()}
and disablePast
, but it didn't work.
codesandbox link here
Thanks in advance.