2
votes

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:

  1. What is the correct syntax to ask this?
  2. Where can I find a list of these strings?
  3. Any alternatives to passing in strings

Thank you.

2
You can only used the strings in the documentation. php.net/manual/en/datetime.formats.relative.phpblupointmedia
What do you mean by start of day? midnight of the current date?blupointmedia
@blupointmedia yes :)party-ring

2 Answers

1
votes

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') }}

0
votes
{{ 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.