I have a PHP function that executes a MySQL query with a few variables defined. I need the BETWEEN clause of the SQL statement to work with the variables, where one of the variables is the DateTime() function.
Here the $start variable should be making a new time and then the value I have in my database should be between this time and the $finish variable i have defined.
$start = new DateTime();
$finish = '2013-10-06 17:06:52';
$value = $this->GetOffset();
$this->db->select("esolar + $value AS Esolar", 1)
->from('calcdata')
->where('siteid', $siteid)
->where("time BETWEEN '$start' AND '$finish'")
->where('esolar <', 1000000)
->where('esolar <>', 0);
$query1 = $this->db->get()->result_array();
$Esolar1 = $query1[0]['Esolar'];
However when I do it I get this error:
A PHP Error was encountered
Severity: 4096
Message: Object of class DateTime could not be converted to string
Thanks
You should do something like:
$start = $start->format('Y-m-d H:i:s');otherwise you will pass an object instead of a string as a parameter