dongtuoao7987 2014-10-17 19:00
浏览 51

Yii framework 2.0 ActiveRecord日期不在两个日期之间

Working with Yii framework 2.0 I have a database table with the columns 'from_date' and 'to_date'. I would like to select and count all records where:

  1. today is NOT between from_date and to_date. And not even equal these dates (!($from_date <= $today) && !($today <= $to_date))).

OR

  1. from_date is NULL and to_date is NULL. Because in some records these dates are empty, they need to be selected and counted as well.

I have a model which extends the ActiveRecord class, so I could use the following code to retrieve the data:

ModelClass::find()-where('big>small')->andWhere('1<2')->orWhere('3>1')->count();

I tried to read the documentation of Yii 2.0 but could not figure out how to use NOT BETWEEN OR EQUAL NULL.

  • 写回答

3条回答 默认 最新

  • doushi1974 2014-10-17 19:55
    关注

    For null, you can use the code below:

    ModelClass::find()->where([
        'from_date' => null,
        'to_date' => null,
    ])
    

    And from the guide, you can easily chain the where attribute: http://www.yiiframework.com/doc-2.0/yii-db-query.html#where%28%29-detail

    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建