PHP / mysql - my timestamp does not like to be in the expression anymore (>)

I have a timestamp in my database with a value: 2011-10-05 16:06:48 , which is greater than the $start variable ( 2011-10-04 13:02:34 ), which I determined when I executed the query . I get an error message.

 function getgeneration() { $period = '1 month'; $siteid = 1; $start = '2011-10-04 13:02:34'; $value = $this->GetOffset(); $this->db->select("esolar + $value AS Esolar") ->from('calcdata') ->where('siteid', $siteid) ->where("time > $start"); $query = $this->db->get()->result_array(); $Esolar1 = $query[0]['Esolar']; echo $Esolar1; return $Esolar1; } 
 A Database Error Occurred 

Error Number: 1064

You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near '13: 02: 34 'on line 4

SELECT esolar + 3 AS Esolar FROM (calcdata) WHERE siteid = 1 AND time > 2011-10-04 13:02:34

File Name: /var/www/test/models/blog_model.php

Line Number: 220

Is this a common issue with timestamps?

+4
source share
3 answers

It seems you need to put quotes around the timestamp, for example:

 SELECT esolar + 3 AS Esolar FROM (calcdata) WHERE siteid = '1' AND time > '2011-10-04 13:02:34' 
+7
source

I think you just need to change

 ->where("time > $start"); 

in

 ->where("time > '$start'"); 
+1
source

Place the timestamp in single or double quotation marks. These are the lines.

0
source

All Articles