【问题标题】:Error: date() expects parameter 2 to be long, string given错误:date() 期望参数 2 很长,给定字符串
【发布时间】:2014-03-27 05:39:37
【问题描述】:

我收到以下代码错误。 请有人帮我解决它。

型号

function getappointmentlist($practicien , $datee) {
            $this->load->helper('date');
            $this->db->select('*');
            $this->db->from('rdv');
            $this->db->join('contact', 'contact.id = rdv.contact_id');
            $this->db->where('people_id',$practicien);
            $this->db->where(date('Y-m-d' , 'day'), $datee);
            $this->db->order_by('startTime', 'ASC'); 
            $query = $this->db->get();
            return $query;
        }

我收到以下错误: 遇到 PHP 错误

Severity: Warning

Message: date() expects parameter 2 to be long, string given

Filename: models/appointment.php

Line Number: 16

Input values :
$practicien = 18
$datee = 2013-05-13

PS:day 是 rdv 表中的一个字段。日期字段中的 ex 数据为:2012-02-15 09:41:35

【问题讨论】:

  • 什么是“天”? db 表中的列?
  • 是的,day 是 rdv 表 ex 数据中的一列:2012-02-15 09:41:35

标签: php mysql codeigniter model


【解决方案1】:
$this->db->where('DATE(day)', $datee);

上面的代码解决了我的问题。 Ramesh 的出色解决方案。

【讨论】:

    【解决方案2】:

    由于'day'是mysql表中的一列,试试

     $this->db->where('DATE(day)', $datee);
    

    【讨论】:

    • 完美运行。非常感谢:)
    【解决方案3】:

    如果您查看文档right here,您会看到日期函数需要时间戳作为第二个参数——它根本不知道如何处理您传入的字符串'day' (date('Y-m-d' , 'day')) .如果你只想要当前时间,请忽略第二个参数。

    【讨论】:

    • rdv 表中的 day 字段包含 2012-02-15 09:41:35 等值
    • 您要在哪个日期获得结果? $datee中的那个?
    • 我在 $datee 有一个输入日期。需要使用它从 rdv 表中获取数据。为此,我正在考虑使用 $datee(date) 在 rdv 表中使用条件 tyo 检查日期字段(datetime)。明白了吗?
    【解决方案4】:

    试试这个:

    $this->db->where(date('Y-m-d' , strtotime('day')), $datee);
    

    并参考这个Warning: date() expects parameter 2 to be long, string given in

    【讨论】:

    • rdv 表中的day字段保存日期和时间的值,ex data : 2012-02-15 09:41:35
    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 2017-01-02
    • 2019-01-22
    相关资源
    最近更新 更多