A few days ago sent a post, is about showing 5 days of this date comparison,
http://www.oso.com.cn/forum/read.php?theme_id=7459
The main argument is to focus on the select something from table
WHERE To_days (now ())-To_days (date_col) < = 5; On, I tried half a day, the result or error, today read the function of MySQL, finally came out of the results, dare not exclusive, posted out for everyone to study, (although the technical content is not high, do not throw my persimmon on the line, hehe)
The To_days (DATE) function of MySQL is as follows:
Returns the total number of days from date to 00, and I tested it.
Mysql>select To_days (now (0));
+--------------------------+
| To_days (Now ()) |
+--------------------------+
| 730839 |
+--------------------------+
Coming out is the total number of days of the current time from 00 A.D., and then I tried to test it with the above statement;
Mysql>select To_days (now ())-To_days (date_col) < = 5;
Results appear:
ERROR 1054:unknown column ' Date_col ' in ' field first '
Blocked, I'm trying to get 5 generations straight to Date_col.
Mysql>select To_days (now ())-to_days (5);
Results appear:
+---------------------------+
|to_days (now ())-to_days (5) |
+---------------------------+
| NULL |
+---------------------------+
Ah? No way? That's not good, is it?
I'll try the order.
Mysql>select ....
Suddenly think, hey, To_days (now ()) come out is an integer, I directly with the integer operation on the line, why again to_days (date)? Test now
Mysql>select To_days (now ())-5;
+--------------------------+
| To_days (now ())-5 |
+--------------------------+
| 730834 |
+--------------------------+
OK, Long live, finally got the result I want, hehe is in the PHP code with select query
My database has always been the habit of DateAndTime with now () direct assignment, when the display is not formatted, directly take out to be able to use,
Here's a partial structure of one of my libraries
CREATE TABLE infomess (
infoid Int (one) not NULL auto_increment,
Topic varchar (255) is not NULL,
......
Email varchar (50),
DateAndTime datetime DEFAULT ' 0000-00-00 00:00:00 ' not NULL,
PRIMARY KEY (infoid)
);
Here DateAndTime is the standard date format, and then I want to query the records within 5 days, here is the SQL query statement
http://www.bkjia.com/PHPjc/632387.html www.bkjia.com true http://www.bkjia.com/PHPjc/632387.html techarticle a few days ago sent a post, is about showing 5 days of this date comparison, http://www.oso.com.cn/forum/read.php?theme_id=7459 main argument is focused on the select something from Tabl ...