Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format time to hh:mm using Twig (Symfony)

Tags:

html

twig

symfony

I retrieve a timefield from my MS SQL database, for example '10:30:00' (hh:mm:ss). I try to render this in a twig template, but I only want to display the '10:30' portion (hh:mm).

I've tried to get this done using both number_format and date_format, but I can't seem to get it done. For example, a failed attempt would be:

<td class="PODTIME">{{ record.PODTIME|number_format(2, ':') }}</td>

Yeah that doesn't make sense. But I can't find anything even remotely close to what I want - I guess I'm overlooking something.

Thanks

like image 467
Kheran Avatar asked Jan 08 '15 10:01

Kheran


1 Answers

You can use the Twig filter date like this :

{{ object.date|date('H:i:s') }}

As seen on this thread : How to render a DateTime object in a Twig template

like image 135
Xavier Norbal Avatar answered Sep 21 '22 11:09

Xavier Norbal