mysql - symfony2 : select from Table where start=today

标签 mysql symfony doctrine-orm

“开始”是日期时间。我试图获取所有具有“start”= Today 的行,而不考虑小时和分钟。 这就是我到目前为止所做的。 仅选择格式为“Y-m-d 00:00:00”的事件

$em = $this->getDoctrine()->getManager();
    $onthisday = $em->createQuery('
        SELECT e
        FROM ECMEventBundle:Events e
        WHERE e.start = CURRENT_DATE()

        AND e.eventcreator = :userId'
    )->setParameter ( 'userId', $user->getId () );

    $todayEvent = $onthisday->getResult();

如有任何回应,我们将不胜感激。

最佳答案

您可以使用 php DateTime 类:

$myDate = new \DateTime();

$em = $this->getDoctrine()->getManager();
    $onthisday = $em->createQuery('
        SELECT e
        FROM ECMEventBundle:Events e
        WHERE e.start > :myDate

        AND e.eventcreator = :userId'
    )->setParameter ( 'userId', $user->getId () )
    ->setParameter ( 'myDate', $myDate->format('Y-m-d 0:0:0') );

关于mysql - symfony2 : select from Table where start=today,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24311664/

相关文章:

postgresql - Doctrine2 : YEAR, PostgreSQL 的 MONTH、DAY 或 DATE_FORMAT

mysql - Symfony2 - 如何根据自定义查询获取实体对象?

MySQL 查询 - IF 或 CASE 以及 AND 和异常(exception)(用于计算)

mysql - 将包含空值的列从 Excel 导入到 MYSQL Workbench 时出现问题

php - 将图像存储在数据库中并检索它以 echo 作为 json

php - 在 Symfony 序列化中更改序列化属性名称

php - 交换 SQL 主键而不影响自增?

php - symfony2 该网页有一个重定向循环

Symfony2 深度列表类别

doctrine-orm - 如何使用 doctrine2 zf2 在 View 助手中获取实体管理器