i have a que开发者_开发技巧ry.this should fetch records created 2 months ago. mysql table type is Innodb. which type do i use for date (time). Datetime or Timestamp int(11) or Timestamp for better performance. records is about 50000-100000.
....
$monthsback = 2;
$date = strtotime("-$monthsback months",time());
$date =date( "Y-m-d H:i:s", $date ); // if i use Datetime
while($result=mysql_fetch_array($r))
{
$recorddate=$result['date'];//fetched from mysql
if ($recorddate>$monthsback)
{
echo "....";
}
else
{
echo "....";
}
}
...
You're only dealing with a hundred thousand records?
Then this qualifies as a micro-optimization.
Pick the column type that best fits the data. DATETIME
is going to end up being the best, most flexible column type for storing date and time information, because that's what it's designed to do.
Change this only when you can prove that another method is faster. Do this by benchmarking and profiling your code to find real bottlenecks.
精彩评论