mysql时间查询
mysql 5.0
create table `actives` (
`starttime` int(11) not null default '0',//此字段为php时间戳
) engine=myisam default charset=gbk;
insert into `actives` values ('1342658714');
insert into `actives` values ('1342858714');
insert into `actives` values ('1343658714');
insert into `actives` values ('1344658714');
insert into `actives` values ('1345658714');
insert into `actives` values ('1346658714');
需要统计出3种类型的结果,
1,查询starttime大于当前服务器时间,并且在 三天内的结果
2,查询starttime大于当前服务器时间,并且在 一周内的结果
2,查询starttime大于当前服务器时间,并且在 一月内的结果
[解决办法]
1,查询starttime大于当前服务器时间,并且在 三天内的结果
select * from actives where starttime between UNIX_TIMESTAMP() and UNIX_TIMESTAMP() + 3*24*60*60;
[解决办法]
mysql> select date_add(now(),interval -1 day);
+---------------------------------+
| date_add(now(),interval -1 day) |
+---------------------------------+
| 2012-07-23 13:20:24 |
+---------------------------------+
1 row in set (0.00 sec)
mysql> select date_add(now(),interval -1 week);
+----------------------------------+
| date_add(now(),interval -1 week) |
+----------------------------------+
| 2012-07-17 13:20:29 |
+----------------------------------+
1 row in set (0.00 sec)
mysql> select date_add(now(),interval -1 month);
+-----------------------------------+
| date_add(now(),interval -1 month) |
+-----------------------------------+
| 2012-06-24 13:20:32 |
+-----------------------------------+
1 row in set (0.00 sec)