[TYPO3-mvc] How to compare a DateTime object correctly inanExtbase query?

Jan Kornblum jan.kornblum at gmx.de
Mon Jan 12 18:12:02 CET 2015


Hi again,

> In TYPO3 Backend, date_published is "5:00 6-1-2015" and in the Database it is 
> "2015-01-06 05:00:00", too. Everything later (Extbase, Fluid) it is 6:00 
> instead of 5:00.
>
>> 2: Using \DateTime is supposed to work
> -> WHERE xyz.date_published < 1420520400
> -> No result at all
>
>> 3: You should be able to use ->format('U') because integers are used plain
> -> WHERE xyz.date_published < '1420520400'
> -> No result at all
>
>> 4: format('Y-m-d H:i:s')
> -> WHERE xyz.date_published < '2015-01-06 06:00:00'
> -> Always the current record (due to the 1 hour difference)
>
>> 5: format('Y-m-d')
> -> WHERE xyz.date_published < '2015-01-06'
> -> Next record
>
>> Is your $datePublished property annotated as "@var \DateTime"? I
> Yes, of course! And the database column is "datetime", too.
>
> Where are the different timezones caused and how can i prevent them?

One ugly workaround:

Setting the timezone "1 hour back" (Europe/London) in php.ini or else 
substracting one hour from the DateTime object directly in the query. 
Then, both queries behave as expected when using format('Y-m-d H:i:s') 
on the DateTime object.

But i can't imagine that something like this should be done. But how 
else? Wouldn't it be better if extbase would ignore the timezone on any 
DateTime comparisons done in database?

Kind regards, Jan




More information about the TYPO3-project-typo3v4mvc mailing list