1

I have a little problem that I can't seem to solve and ask for your help please: I have a branch variable which only contains hour, minute and second with no date. The problem is that its format is h: m: s is I would like to convert it to hh: mm: ss

My variable is : {{hours}} which contains for example: 1:5:7 is i would like to get a result 01:05:07.Can you help me please.

Note that I do not have access to the symfony4 controller because I am a designer thank you in advance.

DevG
  • 13
  • 3

1 Answers1

0

You can do it using date anyways:

{% set hours = "1:2:3" %}
{{ hours|date('H:i:s') }}

#01:02:03
Agnohendrix
  • 480
  • 1
  • 7
  • 17
  • Thanks it works fine, but if the data comes from a dynamic array how do we do it? for example: var value = { "1": "1:0:0", "2": "1:5:4", "3": "3:6,10",.... }; {% for x in value %} {% set hours = x %} {{ hours|date('H:i:s') }} {% endfor %} – DevG May 14 '21 at 13:03
  • just print `{{ x|date('H:i:s') }}` inside your for cycle. – Agnohendrix May 14 '21 at 13:44
  • I found my error, my variable contains a space which causes a bug, so I delete the space with {% set hours = value|replace({' ': ''}) %} is it works thank you very much, my problem is solved. – DevG May 14 '21 at 13:52