TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
我们的date_col必须是日期时间格式,而不能是时间戳,
mysql> SELECT FROM_UNIXTIME(875996580);
-> '1997-10-04 22:23:00'
day(FROM_UNIXTIME(1277709862))这个返回的是某个时间戳到现在经过的天数
获取 日:day(FROM_UNIXTIME(add_time))
获取 月:month(FROM_UNIXTIME(add_time))
获取 年:year(FROM_UNIXTIME(add_time))
sql文里面获得时间戳后格式化为日,月,年:day(now()),month(now()),year(now())
其中add_time是字段名,存放格式为linux时间戳.
mysql> set @a = unix_timestamp();
Query OK, 0 rows affected (0.00 sec)
mysql> select @a;
+------------+
| @a |
+------------+
| 1154942084 |
+------------+
1 row in set (0.00 sec)
mysql> select from_unixtime(@a);
+---------------------+
| from_unixtime(@a) |
+---------------------+
| 2006-08-07 17:14:44 |
+---------------------+
1 row in set (0.00 sec)