[TYPO3-mvc] How to compare a DateTime object correctly in anExtbase query?
Jan Kornblum
jan.kornblum at gmx.de
Mon Jan 12 16:02:00 CET 2015
Hi again,
> As the findPrevious() works fine using this:
>
> $query->setOrderings(array('datePublished' =>
> \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
> $query->matching($query->greaterThan('datePublished',
> $post->getDatePublished()->format('Y-m-d H:i:s')));
>
> ...and findNext() always returns the same (not the next) object as the object
> given as param to compare against in in the query:
>
> $query->setOrderings(array('datePublished' =>
> \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
> $query->matching($query->lessThan('datePublished',
> $post->getDatePublished()->format('Y-m-d H:i:s')));
>
> ...I believe that the problem is located in the fact, that the comparison
> isn't matching exactly (just nearly) because of the wrong format ("maybe some
> seconds / milliseconds are missing?")
O.K. i've figured out at least one thing:
findNext() returning the same object as the given object only happens
when the given object itself has got a DateTime close to midnight
(23:30 01-01-2015). So this really seems to be a timezone problem.
But i still don't understand why the first query needs format('Y-m-d
H:i:s') to behave correctly while the second query only works
"halbwegs" when using ->format('Y-m-d'). And non of the queries work
without format().
Sometimes Extbase really is frustrating... Especially when trying to
accomplish such basic things.
Kind regards, Jan
More information about the TYPO3-project-typo3v4mvc
mailing list