dqrsceg6279196 2017-09-02 11:40
浏览 124
已采纳

将Start_date与SQL中的当前日期进行比较

I need to compare start_date to current_date so that i could found the data of the particular day(In other words: data of the day). For this, i am using this query

    $rs = $this->db->select('ult_camp.*')
                    ->order_by('ult_camp.start_date', 'desc')
                    ->from('ult_camp')
                    ->where('ult_camp.status', 'Active')
                    ->where('date(ult_camp.start_date)<=', date('Y-m-d h:m:s'))
                    ->get()->result();
    return $rs;

But this query i'm getting the data whose start_date is less than the current date.Please Help me to get this.

Any help will be appreciated. Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongzongpeng6474 2017-09-02 11:56
    关注

    You can add another where to get the date range for the day starting 12:00:00 until the present time.

     $rs = $this->db->select('ult_camp.*')
                    ->order_by('ult_camp.start_date', 'desc')
                    ->from('ult_camp')
                    ->where('ult_camp.status', 'Active')
                    ->where('date(ult_camp.start_date)<=', date('Y-m-d h:i:s'))
                    ->where('date(ult_camp.start_date)>=', date('Y-m-d 00:00:00'))
                    ->get()->result();
    return $rs;
    

    This where clause should translate to:

    date(ult_camp.start_date) <= '2017-09-02 08:55:20' AND date(ult_camp.start_date) >= '2017-09-02 00:00:00'
    

    Note: i -> is for minutes and m -> is for month in php date formats

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web