[Solved in Pro 6.5] Unix timestamp format doesn't work

I came accross this post: API Weather App Example and Suggestions where this documentation is mentioned: https://theme.co/docs/dynamic-content#formatting

Does this still work? Because I try to format a unix timestamp but it doesn’t convert the date, but rather takes the current date-time.

What I have is this:
String is 1725096322 as a looper.
I call it with {{dc:looper:item}}. So far so good. When I change it to {{dc:looper:item type="date"}} or {{dc:looper:item type="date" format="d F Y"}}it outputs the current date-time instead of the string (currently 07-06-2024) instead of 31-08-2024.

Am I doing something wrong here?

Hello @Dagaloni,

Thanks for writing to us.

To help you with your concerns we need to check your settings, I would request please share the admin login details meanwhile I would suggest you troubleshoot a few of the common issues before we investigate your settings. Please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin-level username and password
  • Exact URL

You can find the Secure Note button at the bottom of your posts

Thanks

Hi there thanks! Can you please first verify this on your part? I tried it on a fresh install and on my production site, both with the same results.

Hey @Dagaloni,

I “think” (correct me if I’m wrong @Themeco) a timestamp can not be converted with type="date" in a dynamic content element.

In fact in my weather example I wrote a simple shortcode plugin to convert a timestamp to a date like this
[date timestamp='1725096322' format='j. F Y']

BUT: Twig to the rescue!

With the new Twig feature you can do it with the date filter: {{ 1725096322 | date }}
You can format the date like this: {{ 1725096322 | date("j. F Y") }}

Just replace the hardcoded timestamp with your looper item data and it should work.
So let’s say in a looper you have the field named mytimestampthat contains your timestamp.

In classic dynamic content you would access it like this:
{{dc:looper:field key="mytimestamp"}

In Twig you would use it like this:
{{ looper.mytimestamp | date("j. F Y") }}

Here is the documentation of Twigs date filter:
https://twig.symfony.com/doc/3.x/filters/date.html

Hey @Dagaloni,

Kindly test out this {{ looper.mytimestamp | date("j. F Y") }} as provided by @Raye. Twig is fully supported in the upcoming Pro 6.5 version by the way.

Cheers.

Oh that’s great! I haven’t played with Twig yet, but it looks promising! I’l wait until Pro 6.5 to implement to conversion of a timestamp. Thanks!

You are most welcome @Dagaloni

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.