What is the way to subtract datetime values in Twig in a view?
I have a starttime and endtime and want to calculate the difference bewtween the endtime and startime.
What is the way to subtract datetime values in Twig in a view?
I have a starttime and endtime and want to calculate the difference bewtween the endtime and startime.
Comments
Comment #2
stinky commentedComment #3
cilefen commentedDoes this answer your question? https://stackoverflow.com/questions/15657687/twig-date-difference
Comment #4
stinky commentedNot really, lol. I', completely new to Twig.
Here's what I tried-- and it doesn't work.
{% set var1 = field_cp1_time_out_1|date("H:i:s") %}
{% set var2 = field_cp1_time_in_1|date("H:i:s") %}
{% set difference = date(var1).diff(date(var2)) %}
{{ difference }}
Comment #5
cilefen commentedI strongly suggest you ask at https://drupal.stackexchange.com/.
Comment #6
cilefen commentedI urge you to use the better support resources.
Comment #7
cilefen commentedSorry: I didn't mean to just close this and I added a webform queue triage message although this is in Drupal Core! I've removed that. But the bottom line is that the Drupal Core issue queue is not ideal for support requests because they usually go unanswered here.
Comment #9
nelo_drup commentedSame problem using diff produces the following error
Calling "diff" method on a "DateTime" object is not allowed in
Comment #10
cilefen commentedhttps://stackoverflow.com/questions/15657687/twig-date-difference