Reputation: 157
How can I add Time in Twig. I want to add time to my date and time (2017-12-12 17:56:22) like +5 hrs +45 min +00 sec and show it in format like (2017-12-12 11:41 PM)
{{ row.bookingDate + add time }}
Upvotes: 1
Views: 2675
Reputation: 8540
Use the date_modify
filter to add time to the date and then the date
filter to show the date in a specific format:
{% set row = {
bookingDate: '2017-12-12 17:56:22',
} %}
{% set dateFormat = 'Y-m-d h:i A' %}
{{ row.bookingDate|date(dateFormat) }}
{{ row.bookingDate|date_modify('+5 hours +45 min')|date(dateFormat) }}
The above code prints this:
2017-12-12 05:56 PM
2017-12-12 11:41 PM
Upvotes: 3