I have changed it now to
$time = date("Y-m-d H:i:s", $lasttime); SELECT * FROM mytable WHERE timediff('$time',time) < 0
and it works fine...
Question
I'm sending the variable "lasttime" via POST to my PHP script. This variable contains a timestamp as a string. In my MySQL database I have a column 'time'. This column has the type 'TIMESTAMP' and by updating the current timestamp is entered.
I want to select all rows from the database which have a timestamp after the timestamp in the variable $lasttime.
My query:
SELECT * FROM mytable WHERE UNIX_TIMESTAMP(time) > '$lasttime'
The problem is, that all rows are returned. How can I fix that?
La solution 3
I have changed it now to
$time = date("Y-m-d H:i:s", $lasttime); SELECT * FROM mytable WHERE timediff('$time',time) < 0
and it works fine...
Autres conseils
If you are passing in $lasttime a string formatted datetime (e.g. 2014-04-19 03:04:05), you have first to normalized it to unixtime: $unixtime = strtotime($lasttime)
Then the sql query will look like SELECT * FROM mytable WHERE UNIX_TIMESTAMP(time) > $unixtime
Is it possible to do it this way?
$time = date("Y-m-d H:i:s", $lasttime);
SELECT * FROM mytable WHERE timediff('$time',time) > 0
time
is the column in the database.