Skip to content

01/01/2027 resolves to 01/01/2026 if locale 'da' is used with dateFormat #6283

@lasserb-oak

Description

@lasserb-oak

Describe the bug
If the datepicker us set up with the locale da and dateFormat dd/MM/YYYY, and the user selects 01/01/2027 from the dropdown, the input field autoformats the input-text to 01/01/2026. The data parsed to onChange is still correct.

To Reproduce

  1. Set up the datepicker like this:
import { useRef, useState } from 'react';
import DatePicker, { registerLocale } from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
import { da } from 'date-fns/locale/da';

registerLocale('da', da);
const DatepickerBug = () => {
   
    const [startDate, setStartDate] = useState(new Date());

    return (

        <DatePicker
            locale={da}
            selected={startDate}
            onChange={(date) => setStartDate(date)}
            dateFormat='dd/MM/YYYY'
        />
    );
};

export default DatepickerBug;

  1. Select 01/01/2027 from the dropdown
  2. The input field show the wrong date, i.e 01/01/2026

Expected behavior
The input field should show 01/01/2027

Screenshots

Image

Desktop (please complete the following information):

  • OS: MACOS Tahoe 26.01 & Windows 11
  • Browser: Firefox, Chrome
  • Version 9.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions