Feature Request: Global Date Format #122
Replies: 7 comments 2 replies
-
Hey @gtolarc — all dates are formatted as full timestamps when saved in the database, but you can actually set which date format you'd like We use As for the collection timestamps, what would the reason be that you'd like to change the way that those display? Those are created by Mongoose and, like the Let me know if I am misunderstanding the request here. Thank you! |
Beta Was this translation helpful? Give feedback.
-
In the case of timestamps, it seems that the format is hardcoded as just div, not react-datepicker. Also date field format is hardcoded as div in list cell. I want to change these parts. @jmikrut |
Beta Was this translation helpful? Give feedback.
-
@jmikrut, @gtolarc is referring to the admin UI, he linked where it is hardcoded in the admin UI. Could expose a collection timestamp option on the collection config, create a date util function and pass in the config option or fallback to the default |
Beta Was this translation helpful? Give feedback.
-
OK so with the timestamps themselves: Can I ask your reason as to why you would want to change the format of how these are output? As these are literally to describe when the document was created and last modified, the currently displayed format seems to be universally applicable, at least in my opinion. But - I can totally understand your reasoning as to why you'd like to change the way that the Like this, for example, to only show the time: {
type: 'date',
name: 'date',
admin: {
components: {
cell: ({ cellData }) => cellData ? format(new Date(cellData), 'h:mm a') : ''
}
}
} I've pictured this above using the What do you think? Does this serve your purpose? |
Beta Was this translation helpful? Give feedback.
-
Update— I think we could pretty easily add a global date format control that would take effect throughout the entire Admin panel. That way dates could be better formatted based on locale and could be customized throughout the whole UI. I think it would be best set on the global level (not per collection). Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Sounds good :) Anyone on this? |
Beta Was this translation helpful? Give feedback.
-
This feature has been released in 0.6.7. There is now a dateFormat property within admin on the Payload config that can be set to any valid date-fns format. |
Beta Was this translation helpful? Give feedback.
-
I wish there was a date format in the collections-timestamps option and the date field option.
Perhaps the following codes are involved.
https://github.com/payloadcms/payload/blob/master/src/admin/components/views/Account/Default.tsx#L141
https://github.com/payloadcms/payload/blob/master/src/admin/components/views/collections/Edit/Default.tsx#L185
https://github.com/payloadcms/payload/blob/master/src/admin/components/views/collections/List/Cell/field-types/Date/index.tsx#L6
Beta Was this translation helpful? Give feedback.
All reactions