MySQL gets 7 days ago data, date comparison

Source: Internet
Author: User



SELECT * FROM news where N_date>unix_timestamp (Subdate (now (), Interval 7
Day)) Order BY N_click Desc





N Days of recording

WHERE To_days (now ())-To_days (Time field) <= N

Today's record

Where date (Time field) =date (now ())

Or

Where To_days (Time field) = To_days (now ());


Query one week:

SELECT * FROM table where Date_sub (Curdate (), INTERVAL 7 day) <= DATE (column_time);

Query one months:

SELECT * FROM table where Date_sub (Curdate (), INTERVAL INTERVAL 1 MONTH) <= DATE (column_time);
---------------------------End-------------------------------------------
Conversion of long time in MySQL
Http://blog.sina.com.cn/s/blog_4f925fc30102elfp.html
In the development, sometimes to facilitate the date time in a long type (seconds) of the database, here to query the data need to be converted.
In MySQL you can just use the From_unixtime function.

Two conversion functions that are included with MySQL:

In the MySQL database, "2009-09-15 00:00:00" is converted to a function listed as a long integer:
Select Unix_timstamp ("2013-03-15 00:00:00") *1000,
Note that the long integer in the MySQL database is less than the number of milliseconds behind the long integer in Java, so multiply by 1000, which is only a few milliseconds.
2. In MySQL database, "1252999488000" (Long data in Java) is converted to date:
Select From_unixtime (1252999488);
"Note": To remove the last three digits.


MySQL gets 7 days ago data, date comparison

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.