{"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>

src=”https:\/\/www.py.it\/countdown-to-<\/a>{{ contact.birthday|date(‘Y-m-d’) }}00:00:00.gif”<\/P>

 <\/P>

 <\/P>

 <\/P>

or:<\/P>

src=”https:\/\/www.py.it\/countdown-to-<\/a>{{ contact.birthday|dateformat(‘%d\/%m\/%Y’, ‘%Y-%m-%dT%H:%M:%S’) }}.gif”<\/P>

 <\/P>

 <\/P>

 <\/P>

None of these attempts have been successful. I would appreciate any insights or suggestions on how to correctly format the date or alternative approaches to dynamically embed a countdown GIF based on a date field.<\/P>

Thank you.<\/P><\/p>\n","protected":false},"excerpt":{"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 style=”text-align:center”> <img style=”background-color:#f8f9fa; border:hidden;” src=”https:\/\/www.py.it\/countdown-to-2024-09-10.gif” alt=”py” rel=”noreferrer” width=”40%”> <\/p> This shows a countdown to September 10, 2024. However, I encountered a problem when trying to make the countdown dynamic based on […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/posts\/337"}],"collection":[{"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":1,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tenxent.net\/index.php\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}