例子
.....
- DROP TABLE IF EXISTS `ha`;
- CREATE TABLE `ha` (
- `id` int(14) NOT NULL AUTO_INCREMENT,
- `data` date DEFAULT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
- /*Data for the table `ha` */
- insert into `ha`(`id`,`data`) values (1,'1990-12-20');
执行
- SELECT (DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW()) - TO_DAYS(DATA)), '%Y') + 0) AS YEAR FROM ha
结果
转载请注明:谷谷点程序 » mysql用生日算出年龄