datetwilioliquid-template

How to get a date in past or future in reference to current date using the date function in Liquid Template?


I am running a CucumberJs test and is trying to pass a file in liquid template as input, and is trying to figure out how to get a date either in past or future from the current system date (when the test runs).

This is how I have defined in liquid template to get the current system date

"{{ "now" | date: "%Y%m%d" }}","{{ "now" | date: "%Y%m%d" }}"

Solution

  • There could be different ways to resolve this, but this is how it can be resolved.

    {{ "now" | date: "%s" | minus: 86400 | date: "%Y%m%d" }}
    

    In this case the date is converted into minutes, so 24hrs into seconds and then minus that to today's date.