Tom
Tom

Reputation: 12988

Twig - convert time from one format to another

I am pulling in a time from a database in the following format 10:00:00

I would like to be able to display this in the following format... 10am

Here's my twig code ...

{{ item.item_start_time }}

Any ideas how i can to this?

Upvotes: 1

Views: 1158

Answers (2)

hek2mgl
hek2mgl

Reputation: 157947

You can follow the twig documentation. It should be:

{{ item.item_start_time|date("ha") }}

For the format specifiers which I'm using, please refer to the documentation of date

Upvotes: 1

Kaushik
Kaushik

Reputation: 2090

date_default_timezone_set('Asia/Kolkata');
$date = '14:00:00';
echo date('hA', strtotime($date));
echo "</br>";
echo date('HA', strtotime($date));

Output

02PM
14PM

h 12-hour format of an hour with leading zeros 01 through 12

H 24-hour format of an hour with leading zeros 00 through 23

Reference date function

Reference Answer on StackOverflow Click Here

Upvotes: 0

Related Questions