Getting the month from a date

Hello,
I’m trying to get the month out of a date element to compare with another date. I’m using the month() function but it echoes the whole date

if ($event->end()->isNotEmpty()):
    echo $event->end()->month();
     ?>

    <br>
  <?php endif ?>

the expected result is 06 but it displays the whole date (2025-06-08)
What am I doing wrong ?

Hi Alice, where did you pick up the ->month field method? It doesn’t exist.

If you use the regular PHP date handler, you can use ->toDate() with m: PHP: DateTimeInterface::format - Manual

$event->end()->toDate('m')

Hello,
Thank you for your answer, it works !
Here is where I found it :