iamthestreets iamthestreets - 4 years ago 235
Twig Question

TWIG date function displaying incorrect datetime

I am displaying a list of datetimes from my database and using twig to format. This was working until today.

If I dump this:

{{ dump(time.clockedIn) }}


I get this:

DateTime {#612 ▼
+"date": "2017-02-03 17:54:20.000000"
+"timezone_type": 3
+"timezone": "America/New_York"
}


When I dump this:
{{ dump(time.clockedIn|date("m/d/Y h:m:s a")) }}


I get this:
"02/03/2017 05:02:20 pm"


I cannot find out why this changed. Any ideas?

Answer Source

Try this instead:

{{ dump(time.clockedIn|date("m/d/Y g:i:s a")) }

As per the Twig date documentation, you should be using g:i:s a. Note that this documentation references PHP's date function, where you'll see the proper format characters that you can use.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download