Reputation: 1871
I am trying to get the start of today's date and time in Twig. I found that you can get the start of the current week by doing the following:
{{ now | date_modify('monday this week')|date('d-m-y H:i:s') }}
So I assume there will be a way to do this for the start of today. So far, I have tried:
{{ now | date_modify('start of day')|date('d-m-y H:i:s') }}
{{ now | date_modify('start of today')|date('d-m-y H:i:s') }}
Which resulted in:
PHP Warning: DateTime::modify(): Failed to parse time string (start of day) at position 0
PHP Warning: DateTime::modify(): Failed to parse time string (start of today) at position 0
I would like to know:
Thank you.
Upvotes: 2
Views: 1324
Reputation: 5005
{{ date('today') | format_datetime() }}
date
(as well as date_modify
) uses PHP’s strtotime
function. today
refers to 00:00:00 of the current day, as stated in PHP’s relative format reference.
Upvotes: 0
Reputation: 36
you can find those strings here: https://www.php.net/manual/en/datetime.formats.relative.php.
So I think what are you looking for is this:
{{ now | date_modify('today') | date('d-m-y h:m:s') }}
Upvotes: 2