SQL query a specified date and time record SQL statement and query an instance
Create a table with the following abc structure:
Create table 'cc'. 'loup '(
'Id' INT (4) not null AUTO_INCREMENT,
'Datetimes 'INT (4) NULL,
'Ipaddress' VARCHAR (20) NULL,
Primary key ('id ')
) ENGINE = MYISAM
Insert data in batches
Insert into 'loup' ('id', 'datetimes ', 'ipaddress') VALUES
(1, 1271865600, '192. 0.0.1 '),
(2, 1271865600, '192. 0.0.1 '),
(3, 1271865600, '192. 0.0.1 '),
(4, 1271865600, '192. 0.0.1 '),
(5, 1271865600, '192. 0.0.1 '),
(6, 1271865600, '192. 0.0.1 '),
(7, 1271952000, '192. 168.0.1 '),
(8, 1271952000, '192. 168.0.1 '),
(9, 1271952000, '192. 168.0.1 '),
(10,127 1952000, '192. 168.0.1 ');
Well, we have all the preparations. Now we want to query the data from.
Note: 1271865600 = 2010-04-23
1271952000 = 2010-04-23
*/
// Database tutorial connection
Mysql tutorial _ connect ("localhost", "root", "root") or die ('database Server Uid or Password Error! ');
Mysql_select_db ('cc') or die ('data! ');
Mysql_query ("set names 'gb2312 '"); // SET the document to be consistent with the database encoding. Otherwise, garbled characters may occur.
$ CurrentTime = mktime );
// Use mktime to read the time cut from
$ SQL = "Select * from loup where datetimes = $ currentTime ";
$ Query = mysql_query ($ SQL );
While ($ rs = mysql_fetch_array ($ query ))
{
Echo $ rs [0], '|', $ rs [1], '|', $ rs [2], "<br/> ";
}
/*
The output result is
1 | 1271865600 | 127.0.0.1
2 | 1271865600 | 127.0.0.1
3 | 1271865600 | 127.0.0.1
4 | 1271865600 | 127.0.0.1
5 | 1271865600 | 127.0.0.1
6 | 1271865600 | 127.0.0.1
Summary:
During database design, we recommend that you use the mktime timestamp to save the data to facilitate addition and subtraction queries. int (4) is enough to save the current time.
Original Site Article Reprinted with the source www. bKjia. c0m China WEB First stop