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...
  • DavidO's avatar
    2 years ago

    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.
    😊