get data from datetime's column
lets say I have a "Datetime" column in DB. It has a data like "2010-10-01 09:12:00". Beside that, i want to make a searching page which have:
<select id="month" name="month">
       <option value="01">01</option>
       <option value="02">02</option>
       ...
</select>
<input type="text" id="year" name="year">
How do i do to get 开发者_高级运维data if i choose month=10 and year=2010?
SELECT * 
FROM   your_table 
WHERE  MONTH(your_date) = '10' AND YEAR(your_date) = '2010';
Be aware that the above won't be able to use an index on your date column, if one exists. To use an index, you'd have to use something like this:
SELECT * 
FROM   your_table 
WHERE  your_date >= STR_TO_DATE(CONCAT('2010', '-', '10', '-01'), '%Y-%m-%d') AND
       your_date < STR_TO_DATE(CONCAT('2010', '-', '10', '-01'), '%Y-%m-%d') + INTERVAL 1 MONTH;
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论