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