Forum Discussion

Rajorigin's avatar
Rajorigin
Specialist
2 years ago

How to convert a string value in JSON payload and using the date filter

Hi fellow Bonfirers,

Hope you are all doing well and kicking goals 🙂 Need some help to convert a string value that is passed in JSON payload " 2023-05-29T00:00:00.000+00:00 " to date for use in SMS. The below liquid  {{event_properties.${due_date} | date: '%e -%b -%Y'}} still outputs the UTC string value 2023-05-29T00:00:00.000+00:00

Cheers | Raj

  • Hi Rajorigin 

    I hope you are kicking goals also! ðŸ¥…

    Is this what you are looking for:
    2023-05-29

    If so try this:

     

    {% assign utcTimestamp = "2023-05-29T00:00:00.000+00:00" %}
    {% assign localTimestamp = utcTimestamp | date: "%Y-%m-%d" %}
    
    {{ localTimestamp }}

     

    It assigns the current value to a variable which allows you to edit it. The second assign variable takes the value you assigned to 'utcTimestamp' and essentially strips off the 'time' portion of the UTC with liquid. You can edit this however you like to get the date to show the way you want.

    Finally, the end result is rendered with liquid. 

    I don't have a similar value to test it with but you can possibly assign your due date custom event property directly to the first assign function. If that doesn't work, assign the custom event property to it's own assign variable and feed it into the above liquid. Basically, assign, on assign, on assign... infinite assign 😆

    Feel free to reach back out if you needed something more. Happy to keep looking at it.
    😊

  • DavidO's avatar
    DavidO
    Strategist II

    Hi Rajorigin 

    I hope you are kicking goals also! ðŸ¥…

    Is this what you are looking for:
    2023-05-29

    If so try this:

     

    {% assign utcTimestamp = "2023-05-29T00:00:00.000+00:00" %}
    {% assign localTimestamp = utcTimestamp | date: "%Y-%m-%d" %}
    
    {{ localTimestamp }}

     

    It assigns the current value to a variable which allows you to edit it. The second assign variable takes the value you assigned to 'utcTimestamp' and essentially strips off the 'time' portion of the UTC with liquid. You can edit this however you like to get the date to show the way you want.

    Finally, the end result is rendered with liquid. 

    I don't have a similar value to test it with but you can possibly assign your due date custom event property directly to the first assign function. If that doesn't work, assign the custom event property to it's own assign variable and feed it into the above liquid. Basically, assign, on assign, on assign... infinite assign 😆

    Feel free to reach back out if you needed something more. Happy to keep looking at it.
    😊

  • Legend DavidO , thank you and sorry for the late revert, was away. I figured this out too and all looks good now. Thanks for your support!!