Widget shows wrong year for formatted field tag

I’m brand new to LWC and I came across this issue while designing a new widget.
I have a multi-day event that crosses from Dec 2026 into Jan 2027, and the values from {date} and {range} all seem fine.

But once I start using field tags to format the dates I get the wrong year for the end date:

Link to preview widget: Livewhale Test | South Texas College

Hi Andrew,

Welcome to developing for LWC! Would you mind sharing the <field syntax you’re trying into a reply here? Then we can take a peek and see if we might have suggestions or insights into how that’s parsing those dates.

Karl

I’m using the following field syntax:
<field var="end_date" date_format="l M j, Y"/>

I’ve got it bolded in my preview page here: https://prtest.southtexascollege.edu/livewhale.html

You can see how the ending year is wrong through Dec. 31, and then it switches to 2027 as of Jan. 1.

Thanks Andrew – here’s what I suspect is happening. Behind the scenes when you use date_format on an XPHP (or Field) variable, LiveWhale converts the existing variable string to a timestamp (strtotime) and then reformats it using the specified format.

I bet one of two things is happening:

  • It looks like end_date is just showing “January 3” with no year
  • Or it could be there’s something in the end_date (maybe it’s some HTML or something about the “until” markup across years) that is confusing that strtotime function behind the scenes.

In either situation, at least as a stopgap, you could try editing the general date format of the widget settings to something more generic (i.e MM-DD-YYYY) and see if that helps date_format=“” get past the confusion. Hope this helps!

You’re right - an end_date field without the date_format attribute was returning just the day and month, no year.

Now that I’m adjusting the widget setting for “Display dates in the format” I’m getting all the right values!

1 Like