Summary of time and date functions commonly used by MySQL

Source: Internet
Author: User
Tags time and date

This article mainly summarizes some commonly used in the actual use of some of the MySQL time and date and conversion function

1.now (): Returns the current date and time

Select Now (); // 2018-04-21 09:19:21

2.curdate (): Returns the current date

Select curdate (); //

3. DayOfWeek (data): Return date data is the day of the week

(1 = Sunday, 2 = Monday ...) 7= Saturday, ODBC Standard)

Select DayOfWeek ('2018---  3

4.weekday (date): Return date data is the day of the week

(0 = Sunday, 1 = Monday ...) 6= Saturday, ODBC Standard)

Select WEEKDAY ('1997-10-04 22:23:00'); // 5

5.dayofmonth (date): Return date is the day of the one month (1-31 range)

Select dayofmonth ('2018-04-21'); //  +

6.dayofyear (date): Returns date is the day ordinal of the year (1-366 range)

Select dayofyear ('2018-01-01'); // 1

7.Month (date): Returns the month value in date

Select Month ('2018-04-21'); // 4

8.dayname (date): Returns the day of the week (English name returned)

Select dayname ('1998-02-05'); // Thursday

9.monthname (date): Returns a date of several months (return in English)

Select monthname ('2018-02-01')//February 

10.quarter (date): Returns the quarter ordinal of a year

Select Quarter ('2018-04-21'); // 2

11.week (Date,first): Returns date is the week ordinal of a year

(The parameter first:0 indicates that Sunday is the beginning of the week, 1 indicates that Monday is the beginning of the week, the default 0)

Select Week ('2018-02-20'//  7Select Week (' 2018-02-20 ',0//7Select Week ('2018-02-20' ,1//8

12.year (date): Returns the year in date (range 1000-9999)

Select Year ('98-02-03'); // 1998

Not finished ...

Summary of time and date functions commonly used by MySQL

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.