iamthestreets
iamthestreets

Reputation: 773

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?

Upvotes: 0

Views: 2448

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

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.

Upvotes: 1

Related Questions