Implemented Improve date() or <xf:date> for templates or store custom field dates as unix timestamps to the day only

frm

Well-known member
I suggest enhancing the date() template function to support PHP-style formatting, or modifying the <xf:date> conditional to include date and format attributes (while retaining time for where it's already used). This would allow it to recognize custom user field dates set in the format 2024-09-12, and format them as something like "September 12, 2024" or "Sep 12, 24", making them more consistent with other dates seen across XenForo

Referenced formatting: https://www.php.net/manual/en/function.date.php.

For the date() function, it could work similarly to PHP, where you could use date($custom_field, 'F j, Y') to output a formatted date like "September 12, 2024".

As for the <xf:date> conditional, it could have a format attribute for something like "F j, Y", and be used like <xf:date date="$custom_field" format="F j, Y" />.

I understand we're working with just the Y-m-d format for user-selected dates in custom fields and the options for formatting are limited since it's not a full timestamp (i.e., we can't include hours, minutes, seconds). However, as it stands, there’s no way to format these dates in a consistent or visually appealing way, similar to dates seen in user profiles (e.g., Join date or Birthday).

Currently, it appears that we're stuck with the 2024-09-12 (Y-m-d/YYYY-MM-DD) format in custom fields without the ability to modify it, despite attempts to replicate the date() function and <xf:date> conditional (which seems to only accept timestamps with the time attribute) used in other templates.

I may be wrong here, but I posed the question with no response and tried to replicate different formats as seen throughout various templates to no avail, so there might be a way to do it that I'm just not seeing.

If there isn't a way to modify a custom user date input, then please expand date() or <xf:date> for this ability.

Edit: Alternatively, you could store the date selected as a UNIX timestamp without hours, minutes, seconds, ... instead of Y-m-d. such as 1726099200 for September 12, 2024.
 
Last edited:
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
Nevermind.

I would suggest updating the manual to have Designers > Template functions.

As there might be even more functions out there available for us to use without us knowing, and only believing conditionals can be used.

No way I could've been able to find
{{ date(date_from_format('Y-m-d', $user.Profile.custom_fields.testDate), 'M d, Y') }}
To display Sep 12, 2024 (or F in the place of M for September 12, 2024)

Without the help of the community
https://xenforo.com/community/threads/date-format-for-custom-thread-fields.225505/#post-1709260 (@Kirby)

Close suggestion, or revamp my suggestion to update the manual accordingly for date display using the date() / date_from_format() functions.
 
Back
Top Bottom