php - Fetching Results with datetime -
i'm trying fetch results between 2 time intervals. i've done before web app built using y-m-d, having problems y-m-d h:i:s. code below (masked of-course security reasons):
$m5b = date('y-m-d h:i:s',mktime(0,0,0,0,0,0,date('y'),date('m'),date('d'),date('h'),date('i')-5,date('s'))); $npm = date('y-m-d h:i:s',mktime(0,0,0,0,0,0,date('y'),date('m'),date('d'),date('h'),date('i')+1,date('s'))); $gm = mysql_query("select * acm lgt !='0000-00-00 00:00:00' , logged between '$m5b' , '$npm'");
i recommend reading on php's strtotime() function , if you're using recent version of php5 datetime object. should clean code no end.
with strtotime()
$t = strtotime('+5 mins'); $mysqlformatted = date('y-m-d h:i:s', $t); with datetime class
$t = new datetime(); $t->modify('+5 mins'); $mysqlformatted = $t->format('y-m-d h:i:s');
Comments
Post a Comment