PHP and MYSQL optimized way to select by date interval -
which fastest way?
a) $query="select id example date_sent>='".$date1."' , date_sent<='".$date2."'";
or
b) $query="select id example date_sent between '".$date1."' , '".$date2."'";
also, faster , better if have date in format '02/12/2010' ?
a) transform in php date format '2010-12-02' , compare directly 'where date_sent>=2010-12-02'
or
b) use mysql function: 'where date>=str_to_date('02/12/2010','%d/%m/%y')'
?
thanks
its faster convert date string whatever native date format sql server uses. don't have run convert function, nor server have run conversion.
between faster, because handled specific code on backend. <= >= generalized code , has tested for. make sure have proper indexes.
use pdo too, $query = "select id example date_sent between ? , ?";
Comments
Post a Comment