Mysql common time functions

Source: Internet
Author: User

Mysql common time functions

Reprinted please indicate the source: curtain roll west wind column (http://blog.csdn.net/ljxfblog)

Recently, I have been playing the game back-end tool for some data statistics work. I have used a lot of mysql time functions, but I forgot it once I used it and it is easy to confuse it, therefore, record the used functions here and complete them gradually.

1. now (), returns the current time format.

> Select NOW ();

> '2017-11-24 18:38:17'

2. CURDATE () returns the current time format.

> Select CURDATE ();

> '2017-11-24'

3, UNIX_TIMESTAMP (), from 'yyyy-MM-DD HH: MM: ss' format time to the number of seconds since January 1, 1970.

> Select UNIX_TIMESTAMP ();

> 1416825969

> Select UNIX_TIMESTAMP ('2017-10-04 22:23:00 ');

> 875996580

4, FROM_UNIXTIME (), from January 1, 1970 8 points since the number of seconds converted to 'yyyy-MM-DD HH: MM: ss' format time, or converted to custom format.

> Select FROM_UNIXTIME (875996580 );

> 1997-10-05 04:23:00

> Select FROM_UNIXTIME (875996580, "% y % m % d ")

> 19971005

5. DATE_FORMAT (), converted from 'yyyy-MM-DD HH: MM: ss' format time to custom format.

> Select DATE_FORMAT (NOW (), "% y % m % d ")

> 141124


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.