-1

I am trying to execute query in CodeIgniter`, this one works:

$this->db->where("DATEDIFF(NOW(), date_and_time) BETWEEN 30 AND 60");

But this shows error my controller doesn't load, what I am doing wrong?

$this->db->where("DATEDIFF(NOW(), date_and_time) BETWEEN" .$number1. "AND".$number2.")";

Type: ParseError

Message: syntax error, unexpected ';', expecting ')'

5
  • Crysis could you show more code to understand your problem.. Commented Sep 18, 2015 at 7:02
  • Iam trying to replace $number1 and $number2 variables instead of 30 and 60. Commented Sep 18, 2015 at 7:03
  • what error is it showing? Commented Sep 18, 2015 at 7:04
  • i cant fetch the error but my page doesnt load, if i comment that line it works. Commented Sep 18, 2015 at 7:08
  • All you need to do is fix the spacing typos and remove the last double quote. $this->db->where("DATEDIFF(NOW(), date_and_time) BETWEEN $number1 AND $number2"); Commented Apr 13 at 23:26

4 Answers 4

2

You missed the space before and after the "AND":

$this->db->where("DATEDIFF(NOW(), date_and_time) BETWEEN " .$number1. " AND ".$number2.")";
Sign up to request clarification or add additional context in comments.

2 Comments

$number1 and $number2 should be in proper mysql date format y-m-d
@saurabh2836: I don't think so as ´DATEDIFF´ returns the number of days between two dates in MySQL.
2

Here my code :

I just make a query as on my own codeigniter project as following code:

$this->db->select();
$this->db->where("DATEDIFF(NOW(), dateCreated) BETWEEN 0 AND 10");
$this->db->get(tb_publishers);

Returned query by codeigniter function last_query() as :

SELECT * FROM (`tb_publishers`) WHERE DATEDIFF(NOW(), dateCreated) BETWEEN 0 AND 10

My output on phpmyadmin as follow

enter image description here

I hope error may occur due to no space around AND statement please correct that one...

Comments

1

TRY this :

$this->db->where( "DATEDIFF (NOW(), date_and_time) BETWEEN ".$number1. " AND ".$number2." ",null, false);

Comments

-1

Finally this one works

 $where=array("DATEDIFF(NOW(), date_and_time) BETWEEN $number1  AND  $number2");                         

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

Thanks for the help and suggestion guys

1 Comment

If this works then the answer above should also work 100% just as fine. stackoverflow.com/questions/32645738/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.