Kirby date() and DateTime() combination : how to?

Hi dear community

I often stumble upon errors manipulating “complex” dates with Kirby. Today’s one is pretty easy to explain.
Why when I write this :

new DateTime('2017-05-22');

it works like a charm, and then when I do this :

new DateTime($event->date('Y-m-d','from'));

I get this error :

DateTime::__construct(): Failed to parse time string (EVENT) at position 0 (T): The timezone could not be found in the database  

I’m pretty sure it is not a timezone declaration - or whatever - issue but a bad syntax. The question is what did I get wrong with dates manipulation ? Do I have to turn date('Y-m-d','from') into a string before using it ? Isn’t the output a basic 2017-05-22 string already ?

To be sure, I’ve obviously checked that date('Y-m-d','from') displays a correct date, and it does.


To contextualize this code, I have a structure fields with several events planned for 2017, with a “from” and a “to” date. I sort them by “from” and compare this date with $now = new DateTime() to check if it is not a passed event. So I’m stuck with the comparison.

Thank you in advance guys !

Could you post your complete code context, please?

does this work?

new DateTime(date('Y-m-d', strtotime($event->from())));

edited: added strtotime