DROP TABLE IF EXISTS `onethink_member`;CREATE TABLE `onethink_member`(`uid`int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',`nickname`char(16) NOT NULL DEFAULT '' COMMENT '昵称',`sex`tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '性别',`birthday`date NOT NULL DEFAULT '0000-00-00' COMMENT '生日',`QQ`char(10) NOT NULL DEFAULT '' COMMENT 'qq号',`score`mediumint(8) NOT NULL DEFAULT '0' COMMENT '用户积分',`login`int(10) unsigned NOT NULL DEFAULT '0' COMMENT '登录次数',`reg_ip`bigint(20) NOT NULL DEFAULT '0' COMMENT '注册IP',`reg_time`int(10) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间',`last_login_ip`bigint(20) NOT NULL DEFAULT '0' COMMENT '最后登录IP',`last_login_time`int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最后登录时间',`status`tinyint(4) NOT NULL DEFAULT '0' COMMENT '会员状态',PRIMARY KEY (`uid`),KEY `status`(`status`)) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='会员表';INSERT INTO `onethink_member`VALUES ('1', 'admin', '0', '0000-00-00', '', '10', '2', '0', '1467965167', '0', '1468205456', '1');INSERT INTO `onethink_member`VALUES ('2', 'test001', '0', '0000-00-00', '', '10', '2', '0', '1487905248', '0', '1487905248', '1');INSERT INTO `onethink_member`VALUES ('3', 'test002', '0', '0000-00-00', '', '10', '2', '0', '1467965167', '0', '1468205456', '1');INSERT INTO `onethink_member`VALUES ('4', 'test003', '0', '0000-00-00', '', '10', '2', '0', '1487905249', '0', '1487905248', '1');INSERT INTO `onethink_member`VALUES ('5', 'test004', '0', '0000-00-00', '', '10', '2', '0', '1487905228', '0', '1487905248', '1');INSERT INTO `onethink_member`VALUES ('6', 'test005', '0', '0000-00-00', '', '10', '2', '0', '1487905268', '0', '1487905248', '1');方法一:SELECT COUNT(*) FROM onethink_member where DATE(FROM_UNIXTIME(reg_time))= CURDATE();方法二:SELECT COUNT(*) FROM onethink_member where DATE_FORMAT(FROM_UNIXTIME(reg_time),'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d');或:SELECT COUNT(*) FROM onethink_member where FROM_UNIXTIME(reg_time,'%Y-%m-%d') = DATE_FORMAT(NOW(),'%Y-%m-%d');方法三:SELECT COUNT(*) FROM onethink_member where TO_DAYS(FROM_UNIXTIME(reg_time))= TO_DAYS(NOW());常用日期函数总结:1. NOW() 函数返回当前的日期和时间。SELECT NOW();
NOW() | CURDATE() | CURTIME() |
---|---|---|
2008-12-29 16:25:46 | 2008-12-29 | 16:25:46 |
4 .FROM_DAYS(N)
给出一个天数 N,返回一个 DATE 值。SELECT FROM_DAYS(729669);5.STR_TO_DATE()把字符串转换为日期。SELECT STR_TO_DATE(now(),'%Y-%m-%d %H:%i:%s');6. DATE_FORMAT()函数用于以不同的格式显示日期/时间数据。SELECT DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s');7.DATE_ADD()函数向日期添加指定的时间间隔。SELECT DATE_ADD(NOW(),INTERVAL 30 DAY);8.DATE_SUB()函数从日期减去指定的时间间隔。SELECT DATE_SUB(NOW(),INTERVAL 30 MONTH);9.EXTRACT()函数用于返回日期/时间的单独部分,比如年、月、日、小时、分钟等等。SELECT EXTRACT(YEAR FROM NOW()); 等价于:SELECT YEAR(NOW());10 .DATEDIFF()函数返回两个日期之间的天数。SELECT DATEDIFF('2017-1-30','2015-2-19') AS DiffDate;11.UNIX_TIMESTAMP()函数把日期转换为时间戳。SELECT UNIX_TIMESTAMP(NOW());12.FROM_UNIXTIME()函数把时间戳转为日期,还可以加上格式化。① SELECT FROM_UNIXTIME(1487919350);② SELECT FROM_UNIXTIME(1487919350,'%Y%m%d');
新闻热点
疑难解答