Formatting Dates for Profile Widgets

Hello,

I am working with profiles with custom fields for dates. When building a widget to display them, the date fields are being rendered out in “MM/DD/YYYY” format. I’d like to change this to something more like “Jan. 24, 2025” (%M. %n, %Y).

I know events have <arg id="date_format"/>, but it doesn’t appear that profiles has that argument (or a field in the CMS editor to define date formats). I did try to add it into the profile widget template I am working with, but I see no effect.

Is there a way to format dates in profile widgets? I tried looking for something like XPHP casts, but I didn’t see anything in the documentation.

Looking ahead, I will also have to include the dates in the profiles details pages. I can’t think that far ahead at the moment, but if anyone has any advice for that context, I’d appreciate it.

Thanks,
Nick

I believe this should work:

<field var="foo" date_format="M. n, Y" />

Not sure it’s documented anywhere though.

The same would work in a details template instead of a widget by using <xphp instead of <field.

That would do it. Thanks Jon.

(Now for more complex logic given I can’t do {Due: |date|} with this…)

In hindsight, the format should be M. j, Y. That’s the second time I’ve glanced at the list of options and not checked “month” and “day”.

Thanks,
Nick

The good thing is you can get pretty complex with logic using <field>.

Thank goodness for the shorthand for simple if/then logic.

<div class="checklist-list-dates">
  <field content="true">
    <if var="profiles_344" value="Highlight"/>
    <content>
      <p>
        <field if="profiles_339">
          <field var="profiles_339" date_format="M. j, Y" />&nbsp;-
          <br/>
        </field>
        <field if="profiles_340">
          <field var="profiles_340" date_format="M. j, Y" /></field>
      </p>
    </content>
    <else content="true">
      <content>
        <field if="profiles_340">
          <span class="checklist-list-due">
            <strong>Due:&nbsp;
              <field var="profiles_340" date_format="M. j, Y" />
            </strong>
          </span>
        </field>
        <field if="profiles_339">
          <br/>
          <span class="checklist-list-available">
            <em>Available:&nbsp;
              <field var="profiles_339" date_format="M. j, Y" />
            </em>
          </span>
        </field>
      </content>
    </else>
  </field>
</div>
1 Like

I was about to say the same.