MySQL query timestamp and date conversion

Source: Internet
Author: User
Tags mysql query timestamp to date

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

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.