I am facing an issue with dates in tsx. The problem lies in the fact that when I set a date like 30/11/0022, it interprets the date as 30/11/1922, which is incorrect.
Here is the input element I have in tsx:
<FormikField name="Birthdate" disabled={FormState.loading}/>
The FormikField is defined as follows:
interface Props {
name: string;
autoFocus?: boolean;
hidden?: boolean;
disabled?: boolean;
component?: React.Component;
label?: string;
className?: string;
disableAutocomplete?: boolean;
}
export const FormikField = ({ ...props }: Props) => {
// code implementation
};
The Birthday type definition can be found here:
Birthdate:{
type: 'date',
defaultvalue: null,
placeholder: 'Set your birthday',
validations: yup.date()
.required('The field is needed')
.min(new Date(new Date().getFullYear() - 120, new Date().getMonth(), new Date().getDate()),
'The birthday cannot be more than 120 years ago')
.max(new Date(new Date().getFullYear() - 1, new Date().getMonth(), new Date().getDate()),
'The birthday cannot be less than 1 year ago.')
}
Is there any way to resolve this issue? Please note that I am using getFullYear()