New to STL: how should one define a fixed date with the code to be able to calculate further with it?
eg date is December, 18th, 2013 (this does not come from input from a customer, but is ‘external’ to him (eg the date where a new tax rule is enforced).
Should this be {% assign Dat_W = ‘2013-12-18’ | Date: ‘%Y/%m/%d’ %} or something else? Thanks!
Which calculation are you trying to do here? If you want it to compare to another date, you can just use <= or >= to see if the date is later or earlier than another date.
Also, here you’ll find some more examples to calculate with days and such.
But again, if you explain what calculation exactly you are trying to do here, I could help you more with it
We use something like this in our standard text template of “bijzonder verslag” to see if the date of the report is or isn’t within 15 days of the date General Meeting :
{% comment %}datum bijzondere kan nooit korter zijn dan 15 dagen voor datum AV; onderstaande controleert dit{% endcomment %}
{% assign datum_av = period.custom.av.datum | date:'%s' %}
{% assign datum_bijz = company.custom.av.datum_bijzonder | date:'%s' %}
{% assign diffSeconds = datum_bijz | minus: datum_av %}
{% assign diffDays = diffSeconds | divided_by: 3600 | divided_by: 24 %}
So the date-tag %s is basically a timestamp in seconds that’s linked to a date (every date gives a separate timestamp in seconds, beginning from somewhere after the seventies I thought).
Anyhow, because of that timestamp, you can calculate to days by dividing by 3600 and 24. If you put that calculation in a variable, you could use something like :
Dit bijzonder verslag is opgesteld door de {% case director_type %}{% when 'zaakvoerder' %} zaakvoerder{% when 'zaakvoerders' %} zaakvoerders{% else %} raad van bestuur{% endcase %} op {% input company.custom.av.datum_bijzonder as:date %}. {% if 15d_voor_datum_av %}{% ic %}{::warningtext}Opgelet! Datum bijzonder verslag kan niet korter zijn dan 15 dagen voor datum AV{:/warningtext}{% endic %}{% endif %}
You’re not going too far with this (on the contrary, I have experience in other programming languages).
Tried it out with success … Thanks … However, now I have other questions:
Suppose you have a start date and you want to calculate and ‘end date’ by first adding 2 days and then 4 years to the start date.
First of all, is there a ‘leap year function’ available so you can determine the exact number of days to add for four years?
Second, once you have calculated the exact number of days to add to the start date and have added them to the start date, how can you easily determine the date from this number? In Excel, this is done by ‘formatting’ your cell. I wonder whether there’s a similar function in Liquid.
Hey Sven, It’s not exactly what I was looking for, but this solution is close enough. Thanks!
Another related question: the date that has to be manipulated by adding 2 days and 4 years, is not user input, but has to be looked up in the details in another accounts template (more exactly the details in the table ‘Oprichtingen en verhogingen’ the accounts template ‘kapitaal’). How can I do this in code?
Because you already have experience with coding, mind to go at it?
If you’re stuck, let us know and we’ll help you forward. If you have it, you can always post the code here. The more we do that, the more everyone can learn