PHP and MySQL Date comparison method _php tutorial

Source: Internet
Author: User
Tags php and mysql
MySQL Date comparison
To_days (now ())-To_days (Date_col) <= 30;
Our date_col must be a DateTime 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 a timestamp has elapsed.

Date taken: Day (From_unixtime (add_time))
Get month: Month (From_unixtime (add_time))
Get Year: Years (From_unixtime (Add_time))
The SQL text inside gets the timestamp after formatting into days, months, years: Day (Today ()), Month (now ()), Year (now ())
Where Add_time is the field name, the storage format is the 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)

http://www.bkjia.com/PHPjc/326265.html www.bkjia.com true http://www.bkjia.com/PHPjc/326265.html techarticle MySQL Date comparison to_days (now ())-to_days (date_col) = 30; Our date_col must be a DateTime format, not a timestamp, MySQL SELECT from_unixtime ( 875996580); -' 1997-10-...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.