
Would anyone know how to get the difference in days between two dates using liquid? I can't figure it out.
{% assign date1 = "12/10/2020 12:00:00 AM" %}
{% assign date2 = "13/10/2020 12:00:00 AM" %}
the output should be 1 - for 1 day between
I have researched a lot and found "date: '%s'" works for normal liquid - but in PowerApps liquid the '%s' represents the seconds.
{% assign date2 = "13/10/2020 12:00:00 AM" | date: '%s' %}
Cheers in advance!
(I am assuming your %s was attempting to get seconds from epoch so you could subtract numbers)
For date objects 'minus' works
Try this Liquid to see the date subtract
{% assign date1 = now %}
{% assign date2 = date1 | date_add_days: -5 %}
Date1: {{ date1 }}<br />
Date2: {{ date2 }}<br />
Subtracted: {{ date1 | minus: date2 }}<br />
You'll notice the output is days:minutes:seconds (so depending on what you need to do you may need to extract what you need and further manipulate it.
For the above I 'stole' ideas from a post in this thread: https://stackoverflow.com/questions/42429448/get-date-difference-using-adx-studio-liquid-template
{% if item.dob %}
{% assign words = now | minus: item.dob | string | split: '.' %}
{% assign days = words.first | integer %}
{{ days | divided_by: 365 }}
{% endif %}
Depending on what you are actually doing, do you need this in Liquid e.g. if it is something on the page you may be able to use Liquid to write JavaScript variables and then do the work in JavaScript.