MySQL Date and Time Function example

Source: Internet
Author: User

The following articles mainly introduce the actual usage of MySQL datetime functions that are frequently used. We all know that MySQL datetime functions are frequently used by all of us, therefore, I have a deeper understanding of its related date and time functions.

DAYOFWEEK (date)

The return date is the day of the week (1 = Sunday, 2 = Monday ,...... 7 = Saturday, ODBC Standard)

Mysql> select DAYOFWEEK ('2017-02-03 ');

-> 3

WEEKDAY (date)

Returns the date of a week (0 = Monday, 1 = Tuesday ,...... 6 = Sunday ).

Mysql> select WEEKDAY ('2017-10-04 22:23:00 ');

-> 5

Mysql> select WEEKDAY ('2017-11-05 ');

-> 2

DAYOFMONTH (date)

Returns the day (within the range of 1 to 31) from January 1, January)

Mysql> select DAYOFMONTH ('2017-02-03 ');

-> 3

MySQL date and Time Function: DAYOFYEAR (date)

Returns the day (within the range of 1 to 366) of a year)

Mysql> select DAYOFYEAR ('2017-02-03 ');

-> 34

MONTH (date)

Returns the month value in date.

Mysql> select MONTH ('2014-02-03 ');

-> 2

DAYNAME (date)

Returns the day of the week by the English name)

Mysql> select DAYNAME ("1998-02-05 ");

-> 'Thursday'

MONTHNAME (date)

Returns the month of the date value (returned by English name)

Mysql> select MONTHNAME ("1998-02-05 ");

-> 'February'

QUARTER (date)

Returns the quarter of the year for date.

Mysql> select QUARTER ('98-04-01 ');

-> 2

WEEK (date, first)

Returns the week number Of The Year for date. (the default value of first is 0. The value of first is 1, indicating that Monday is the start of the week, and 0 starts from Sunday ). The above content is an introduction to the MySQL date and time functions. I hope you will have some gains.

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.