In the use of the database, it is often necessary to query records by a specified date, in order to facilitate statistics, and in the database, there are many stored in the timestamp,
There is also a direct deposit date, the query may not be so good to get.
MySQL provides two functions:
From_unixtime (time_stamp), convert timestamp to date
Convert a specified date or date string to a timestamp, unix_timestamp (date)
[Plain] Select From_unixtime (1382544000); +---------------------------+ | from_unixtime (1382544000) | +---------------------------+ | 2013-10-24 00:00:00 | +---------------------------+ such as: Unix_timestamp (date) [plain] Select Unix_timestamp (Date (' 2013-10-24 ')); +------------------------------------+ | unix_timestamp (Date (' 2013-10-24 ')) | +------------------------------------+ | 1382544000 | +------------------------------------+ If you want to query the records of orders for the day: [Plain] SELECT COUNT (*) from B_order Where Date_ Format (From_unixtime (create_time), '%y-%m-%d ') = Date_format (now (), '%y-%m-%d ') is also possible: [Plain] SELECT count (*) From B_order Where create_time >= unix_timestamp (' 2013-10-24 00:00:00 ') and Create_time <= unix_ Timestamp (' 2013-10-24 23:59:59 ');
MySQL query timestamp and date conversion