gpt4 book ai didi

php - 如何在两个字符串值之间绑定(bind)日期时间字段

转载 作者:行者123 更新时间:2023-11-29 02:15:27 25 4
gpt4 key购买 nike

我有这样的方法:

public function getCustomDateOrders(string $startDay,string $endDay,string $food) :array
{
$result = $this->_em->createQueryBuilder()
->select
(
'OrderEntity.name'
'OrderEntity.created'
)
->from($this->entityClass , 'OrderEntity')
->leftJoin(
'Directory\Food',
'Food',
'with',
'Food.id = OrderEntity.FoodId '
)
->where("Food.id =:food")
->andWhere("OrderEntity.status =:active")
->andWhere("startDate<:OrderEntity.orderCreated >:endDay")
->getQuery()
->setParameters([
"food" => $food,
"active" => 1,
"startDate" => $startDay,
"endDay" => $endDay
])
->getScalerResult();

->getScalarResult();

}

我有几个值:

$startDay 等于 "2016-010-17 00:00:00" (字符串)

$endDay 等于 "2016-10-03 00:00:00" (字符串)

order.created(order 的字段之一)也是datetime

我想从订单实体中获取订单,该订单实体创建的字段在 $startDay$endDay 之间。如何解决?

最佳答案

之间使用:

public function getCustomDateOrders(string $startDay,string $endDay,string $food) :array
{
$result = $this->_em->createQueryBuilder()
->select
(
'OrderEntity.name'
'OrderEntity.created'
)
->from($this->entityClass , 'OrderEntity')
->leftJoin(
'Directory\Food',
'Food',
'with',
'Food.id = OrderEntity.FoodId '
)
->where("Food.id =:food")
->andWhere("OrderEntity.status =:active")
->andWhere("OrderEntity.orderCreated between :startDay and :endDay")
->setParameters([
"food" => $food,
"active" => 1,
"startDay" => $startDay,
"endDay" => $endDay
])
->getQuery()
->getScalerResult();
}

关于php - 如何在两个字符串值之间绑定(bind)日期时间字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40485404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com