About MySQL common time functions

Source: Internet
Author: User

Reprint Please indicate the source: The Curtain Roll westerly column (Http://blog.csdn.net/ljxfblog)

Recently has been doing some of the game backstage tools about data statistics work, for MySQL time function used more, but used to forget, and easy to confuse, so in this record the use of functions, later gradually complete.

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

> select now ();

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

2, Curdate (), returns the current time format.

> select Curdate ();

> ' 2014-11-24 '

3, Unix_timestamp (), converted from ' yyyy-mm-dd HH:MM:SS ' to the number of seconds since January 1, 1970 8 o'clock.

> select Unix_timestamp ();

> 1416825969

> select Unix_timestamp (' 1997-10-04 22:23:00 ');

> 875996580

4, From_unixtime (), from January 1, 1970 to 8 o'clock since the number of seconds converted to the ' yyyy-mm-dd HH:MM:SS ' lattice -style time, or convert it into a 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 a custom format.

> select Date_format (Now (), "%y%m%d")

>141124


About MySQL common time functions

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.