Heim  >  Artikel  >  Backend-Entwicklung  >  PHP以及MYSQL日期比较方法_PHP教程

PHP以及MYSQL日期比较方法_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:14:18929Durchsuche

MYSQL日期比较
TO_DAYS(NOW()) - TO_DAYS(date_col) 我们的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)

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/326265.htmlTechArticleMYSQL日期比较 TO_DAYS(NOW()) - TO_DAYS(date_col) = 30; 我们的date_col必须是日期时间格式,而不能是时间戳, mysql SELECT FROM_UNIXTIME(875996580); - '1997-10-...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn