react-datepicker
react-datepicker copied to clipboard
Escape characters with square brackets not working in dateFormat prop
Describe the bug
As I understood, react-datepicker
uses date-fns
under the hood for formatting dates, localization and so on. I'm trying to escape some characters in the dateFormat
prop but it's not working. I tried to scape using square brackets (as described here in date-fns
doc) but also with: \\
, {}
and ()
.
Example
<DatePicker
selected={parseISO(date)}
maxDate={maxDate}
locale="pt"
customInput={<CustomInput />}
dateFormat="dd [de] MMMM [de] yyyy"
onChange={(date) =>
Array.isArray(date)
? onChangeDateRequest(date[0])
: onChangeDateRequest(date)
}
{...rest}
/>
Additional context
It is a bug or react-datepicker
doesn't support this? Because I think it's something worth to support.
Were you able to solve this problem?
Were you able to solve this problem?
Unfortunately no, I decided to go for "dd/MM/yyyy"
😢 and no answers at all too. Bad.
can this feature be added?
seems like we can use single quotes to escape characters, according to docs: https://date-fns.org/v2.0.0-alpha.27/docs/format
The characters wrapped between two single quotes characters (') are escaped. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)
That worked for me:
<DatePicker dateFormat="yyyy-MM-dd'T'HH:mm" ... />
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.