Skip to main content

I have an API-triggered broadcast that have date attributes, “EffectiveDate”, “UpdateDate”.

In the message I want to send out in my broadcast, I would like to format these dates according to the user’s locale which is in the user record.  

For example, I would like the following:
 

  • For long dates:

    • en-US:  June 17, 2024

    • en-CA:  June 17, 2024

    • fr-CA:  17 juin 2024

    • de-DE:  04. Oktober 2024

       

  • For short dates:

    • en-US:  10/04/2024

    • en-CA:  2024-10-04

    • fr-CA:  2024-10-04

    • de-DE: 04.10.2024

How do I accomplish this?  

Hi @atrivino ,

For API-triggered broadcasts, you can reference to the trigger dates using the trigger Liquid syntax as outlined here.

To achieve your use case, you would need to use Liquid conditionals and filters:

Here’s a quick example, for the short dates:

{% if customer.locale == ‘en-US’ %}{{trigger.timestamp | date: ‘%d/%m/%Y’}}

{% elsif customer.locale == ‘en-CA’%}{{trigger.timestamp | date: ‘%Y-%m-%d’}}

{% elsif customer.locale == ‘fr-CA’%}{{trigger.timestamp | date: ‘%Y-%m-%d’}}

{% elsif customer.locale == ‘de-DE’%}{{trigger.timestamp | date: ‘%d.%m.%Y’}}

{% endif %} 

 

You might also wish to add a {% else %} fallback as a catchall on the date format for profiles without a locale attribute as well (before the {% endif %}

 

For the long dates, due to the different languages, you would need to use more complex custom Liquid statements to define the conditions for how to render the months in the local languages. 

Hopefully this helps to move you along in the right direction! 

 


Reply