DROP TABLE IF EXISTS `times`;
CREATE TABLE `times` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`date1` timestamp NULL DEFAULT NULL,
`isPass` int(11) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=gb2312;#
# Dumping data for table times
#
LOCK TABLES `times` WRITE;
/*!40000 ALTER TABLE `times` DISABLE KEYS */;INSERT INTO `times` VALUES (1,'2010-05-17 11:20:28',0);
INSERT INTO `times` VALUES (2,'2010-05-13 14:34:04',0);
INSERT INTO `times` VALUES (3,'2010-05-13 14:34:31',0);
检查一下date1字段时间是否是今天发生的,如果是isPass字段更新为1,如果不是则默认为0
得到结果为
id isPass
1 1
2 0
3 0
+----+---------------------+--------+
| Id | date1 | isPass |
+----+---------------------+--------+
| 1 | 2010-05-17 11:20:28 | 0 |
| 2 | 2010-05-13 14:34:04 | 0 |
| 3 | 2010-05-13 14:34:31 | 0 |
+----+---------------------+--------+
3 rows in set (0.00 sec)mysql> select id,date(date1)=curdate()
-> from `times`;
+----+-----------------------+
| id | date(date1)=curdate() |
+----+-----------------------+
| 1 | 1 |
| 2 | 0 |
| 3 | 0 |
+----+-----------------------+
3 rows in set (0.08 sec)
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from times;
+----+---------------------+--------+
| Id | date1 | isPass |
+----+---------------------+--------+
| 1 | 2010-05-17 11:20:28 | 1 |
| 2 | 2010-05-13 14:34:04 | 0 |
| 3 | 2010-05-13 14:34:31 | 0 |
+----+---------------------+--------+
3 rows in set (0.00 sec)
curdate()) 今天的日期
date(date1) =curdate() , 如果相等,则返回1,否则返回0