0

So basically I have a TIMESTAMPDIFF query in my model to determine the duration and I want it to display the duration in a view. The problem is, it will display the error.

Please help me, thank you.

Here's my query of my model (model_attendance.php):

public function getOne($username){
        $sql = "SELECT empnum FROM employees WHERE username='$username'";

        $result = $this->db->query($sql);

        $sql1 = "SELECT a.empnum,CONCAT(a.name,' ',a.midname,' ',a.lastname) AS
                NAME,CONCAT(b.indate,' ',b.intime) AS 'TIMEIN',CONCAT(b.outdate,'
                ',b.outtime)AS 'TIMEOUT', TIMESTAMPDIFF(HOUR, 'TIMEIN','TIMEOUT') AS 'DUR' 
                FROM employees AS a
                JOIN times AS b ON (a.empnum=b.userid)
                WHERE b.indate BETWEEN
                DATE(CONCAT(YEAR(CURRENT_TIMESTAMP),'-',MONTH(CURRENT_TIMESTAMP),'-','01'))
                AND DATE(LAST_DAY(CURRENT_TIMESTAMP)) AND b.userid='".$result->row(0)->empnum."'";

        $query = $this->db->query($sql1);

        return $query->result();
    }

3 Answers 3

1

To solve this problem, you need to Pass return type as "false" to Active record select query.

$this->db->select("TIMESTAMPDIFF(YEAR,a.date_birth, CURDATE()) AS age", false);
Sign up to request clarification or add additional context in comments.

Comments

0

Assign that to variable and pass that to your SQL Query.

$now = date('Y-m-d H:i:s'); # 2015-1-30 04:32:25 / With time
$now = date('Y-m-d'); # 2015-1-30 / Without time

Comments

0

Its potentially a bug. I Havent checked the Query Builder class yet. But to fix this...you can try by adding ` to the column like this

$this->db->select("TIMESTAMPDIFF(YEAR, `a.date_birth`, CURDATE()) AS age");

or

$this->db->query("TIMESTAMPDIFF(YEAR, `a.date_birth`, CURDATE()) AS age");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.