Home >Backend Development >PHP Tutorial >PHP and MYSQL date comparison method_PHP tutorial

PHP and MYSQL date comparison method_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:14:18977browse

MYSQL date comparison
TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
Our date_col must be in date time format, not a timestamp,

mysql> SELECT FROM_UNIXTIME (875996580);
-> '1997-10-04 22:23:00'

day(FROM_UNIXTIME(1277709862)) This returns the number of days that have passed since a certain timestamp

Get the day: day(FROM_UNIXTIME(add_time))
Get the month: month(FROM_UNIXTIME(add_time))
Get the year: year(FROM_UNIXTIME(add_time))
After getting the timestamp in the sql text Formatted as day, month, year: day(now()), month(now()), year(now())
where add_time is the field name, and the storage format is linux timestamp.

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 date comparison TO_DAYS(NOW()) - TO_DAYS(date_col) = 30; Our date_col must be a date time Format, not timestamp, mysql SELECT FROM_UNIXTIME(875996580); - '1997-10-...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn