Hax0r
Hax0r

Reputation: 1823

Codeigniter SQL Query Syntax

I'm using Codeigniter3 and have a problem with an query

The default value of the variable day is 14. I want to convert sql query below to the codeigniter model below.

(CONVERT_TZ(CreateTime,'+0:00','+9:00') > DATE_ADD( CONVERT_TZ(NOW(),'+0:00','+9:00') , INTERVAL -".$day." DAY )

OR CONVERT_TZ(CreateTime,'+0:00','+9:00') > DATE_ADD( CONVERT_TZ(NOW(),'+0:00','+9:00') , INTERVAL -".$day." DAY ) )

This is the model I wrote and it gives error

$where["CONVERT_TZ(CreateTime,'+0:00','+9:00') > DATE_ADD( CONVERT_TZ(NOW(),'+0:00','+9:00'),"] = "INTERVAL -".$day." DAY";

foreach ($where as $key => $value) {
   $this->db->where($key,$value);
}

Upvotes: 4

Views: 489

Answers (1)

Hikmat Sijapati
Hikmat Sijapati

Reputation: 6969

Try like this..

 $where = "(CONVERT_TZ(CreateTime,'+0:00','+9:00') > DATE_ADD( CONVERT_TZ(NOW(),'+0:00','+9:00') , INTERVAL -".$day." DAY )
           OR CONVERT_TZ(CreateTime,'+0:00','+9:00') > DATE_ADD( CONVERT_TZ(NOW(),'+0:00','+9:00') , INTERVAL -".$day." DAY ))";

  $this->db->where($where);

For more see Codeigniter Query Builder

Upvotes: 5

Related Questions