Compare DATETIME with time() in php and mysql -


i check how many users online on moment on single query. thing have time kept datetime (in online field) , compare time(). here code:

$online_margin = 10; //in minutes;  $online_margin = $online_margin*60; $difference = time() - $online_margin;  $query = "select id users online > $difference"; 

i've tried using convert() , cast failed, i'd appreciate on why...

you need convert y-m-d h:i:s format before comparing db field,

$online_margin = 10; //in minutes;  $online_margin = $online_margin*60; $difference = time() - $online_margin; $difference  = date("y-m-d h:i:s",$difference); //convert seconds y-m-d h:i:s format $query = "select id users online > $difference"; 

alternative: can convert column online unix_time comparing,

$query = "select id users unix_timestamp(online) > $difference"; 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -