php - Cakephp MYSQL查询: SELECT where date is greater than

标签 php mysql sql datetime cakephp

我必须运行 MYSQL 选择查询,其中查询返回开始日期为今天 10 天后的所有值。这两种方法我都试过了,都不行,请问哪里需要修改?

$fix_d_table = TableRegistry::get('fixed_departures');
$f_dates_march = $fix_d_table   ->find("all")
    ->where(['trek_id' => 3])
    ->andWhere(['month(date_from)' => 03])
    ->andWhere(['date_from' >= date("Y-m-d",strtotime("+10 days"))])
    ->order(['date_from'=>'asc'])
    ->select(['date_from', 'date_to', 'seats_available','id'])
    ->toArray();

$fix_d_table = TableRegistry::get('fixed_departures');
$f_dates_march = $fix_d_table   ->find("all")
    ->where(['trek_id' => 3])
    ->andWhere(['month(date_from)' => 03])
    ->andWhere(['date(date_from)' >= date("Y-m-d",strtotime("+10 days"))])
    ->order(['date_from'=>'asc'])
    ->select(['date_from', 'date_to', 'seats_available','id'])
    ->toArray();

最佳答案

尝试下面的一个

$fix_d_table = TableRegistry::get('fixed_departures'); $f_dates_march
= $fix_d_table   ->find("all")
    ->where(['trek_id' => 3])
    ->andWhere(
        function ($exp) {
            return $exp->or_([
                'date_from <=' => date('Y-m-d', strtotime("+10 days")),
                'date_from >=' => date('Y-m-d')
            ]);
    })
    ->order(['date_from'=>'asc'])
    ->select(['date_from', 'date_to', 'seats_available','id'])
    ->toArray();

关于php - Cakephp MYSQL查询: SELECT where date is greater than,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49443212/

相关文章:

php - 如何使用两个表laravel从同一数据库中获取数据

c# - Group By 统计相同状态值的总数

sql - 如何从 SQL Server 中的表中获取行索引?

javascript - PHP var->Javascript->PHP

php - 在 WooCommerce 中的购物车和结账页面上显示购买备注和属性

mysql - 执行选择限制字符长度不会返回空值

php - 使用条件语句在多个表上使用左连接

javascript - 如果单击“确定”更新数据库中的 2 行,则会发出警报,否则不执行任何操作

php - 已安装 ffmpeg 但我收到 "no such file or directory"错误

php - 如何从 Laravel 5 的内核中删除旧的 artisan 命令