{"id":337,"date":"2024-09-02T12:24:19","date_gmt":"2024-09-02T12:24:19","guid":{"rendered":"https:\/\/tenxent.net\/?p=337"},"modified":"2024-09-02T14:36:43","modified_gmt":"2024-09-02T14:36:43","slug":"dynamic-gif-countdown-based-on-date-picker-field","status":"publish","type":"post","link":"https:\/\/tenxent.net\/index.php\/2024\/09\/02\/dynamic-gif-countdown-based-on-date-picker-field\/","title":{"rendered":"Dynamic GIF Countdown based on Date Picker field"},"content":{"rendered":"
I’m working on embedding an animated GIF into an email that displays a countdown timer. The static version works perfectly using the following HTML code:<\/P>
<\/P><p style=”text-align:center”>
\n <img style=”background-color:#f8f9fa; border:hidden;”
\n src=”https:\/\/www.py.it\/countdown-to-2024-09-10.gif”
\n alt=”py”
\n rel=”noreferrer”
\n width=”40%”>
\n<\/p>
<\/P>
This shows a countdown to September 10, 2024. However, I encountered a problem when trying to make the countdown dynamic based on a date picked from a date picker field linked to a contact\u2019s birthday. The modified code is:<\/P>
<\/P><p style=”text-align:center”>
\n <img style=”background-color:#f8f9fa; border:hidden;”
\n src=”https:\/\/www.py.it\/countdown-to-{{contact.birthday}}00:00:00.gif”
\n alt=”py”
\n rel=”noreferrer”
\n width=”40%”>
\n<\/p>
<\/P>
The contact.birthday field outputs the date in the dd\/MM\/YY format (e.g., 10\/09\/24 for September 10, 2024), which doesn’t work with the URL structure my GIF requires.<\/P>
I’ve attempted several methods to format the date correctly, including:<\/P>
{% set date_parts = contact.birthday.split(‘\/’) %}
{% set year_full = “20” + date_parts[2] %}
{% set new_date = year_full + “-” + date_parts[1] + “-” + date_parts[0] %}<\/P>
<\/P>
<\/P>
<\/P>
And using filters like:<\/P>