56,866
社区成员




mysql> select * from d;
+---------------------+
| d |
+---------------------+
| 2009-07-05 15:20:10 |
| 2009-07-14 10:30:00 |
| 2009-04-20 05:15:40 |
+---------------------+
3 rows in set (0.00 sec)
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("csdn",$conn);
$year = "2009-05-12";
$sql = "select * from d where year(d)=year('$year')";
echo $sql;
mysql_query("set names gbk",$conn);
$result = mysql_query($sql,$conn);
while($row = mysql_fetch_array($result)){
echo $row[0];
}
?>
mysql> set @a='2009/08/07';
Query OK, 0 rows affected (0.00 sec)
mysql> select year(@a);
+----------+
| year(@a) |
+----------+
| 2009 |
+----------+
1 row in set (0.00 sec)