Typo3 如何比较Extbase存储库中的日期时间
我尝试将事件的开始日期与当前日期进行比较,以便只显示下一个事件。这是我在eventRepository中的尝试:Typo3 如何比较Extbase存储库中的日期时间,typo3,extbase,Typo3,Extbase,我尝试将事件的开始日期与当前日期进行比较,以便只显示下一个事件。这是我在eventRepository中的尝试: public function findNext() { $query = $this->createQuery(); $query->matching( $query->greaterThanOrEqual('datum_beginn', new \DateTime('midnight')) ); return $q
public function findNext() {
$query = $this->createQuery();
$query->matching(
$query->greaterThanOrEqual('datum_beginn', new \DateTime('midnight'))
);
return $query->execute();
}
但结果并不像预期的那样。这是生成的查询:
SELECT events.* FROM events WHERE events.datum_beginn >= 1413669600 AND ...
如您所见,DateTime被转换为时间戳。如何在查询中使用MySQL NOW()或正确使用DateTime?使用日期的字符串值:
public function findNext() {
$query = $this->createQuery();
$date = new \DateTime('midnight');
$query->matching(
$query->greaterThanOrEqual('datum_beginn', $date->format('Y-m-d H:i:s'))
);
return $query->execute();
}
在9 LTS中,可以直接与日期时间进行比较:
$query->greaterThanOrEqual('datum_beginn', new \DateTime)
这对我不起作用(Extbase 6.2)。我不得不改用$date->getTimestamp()。@biesior:你太棒了。我几乎从你的回答中得到了一切。干杯!:)实际上,这取决于数据库中存储的格式,它可能是unix时间戳或MySQL时间戳。。。OP遇到了问题,因为他使用了第二种格式,所以将其与unix时间戳(
$date->getTimestamp()
)进行比较没有意义