MySQL Date time function

Source: Internet
Author: User


DayOfWeek (date)
Return date is the day of the week (1= Sunday, 2 = Monday,...... 7= Saturday, ODBC Standard)
Mysql> Select DayOfWeek (' 1998-02-03 ');
-> 3
Weekday (date)
Return date is the day of the week (0= Monday, 1 = Tuesday,...... 6= Sunday).
Mysql> Select Weekday (' 1997-10-04 22:23:00 ');
-> 5
Mysql> Select Weekday (' 1997-11-05 ');
-> 2
DayOfMonth (date)
Returns date is the day ordinal of January (within 1 to 31)
Mysql> Select DayOfMonth (' 1998-02-03 ');
-> 3
DayOfYear (date)
Return date is the day ordinal of the year (within 1 to 366)
Mysql> Select DayOfYear (' 1998-02-03 ');
-> 34
MONTH (date)
Returns the number of months in date
Mysql> Select MONTH (' 1998-02-03 ');
-> 2
Dayname (date)
Return date is the day of the week (returned by English name)
Mysql> Select Dayname ("1998-02-05");
-> ' Thursday '
MonthName (date)
Return date is a few months (returned by English name)
Mysql> Select MonthName ("1998-02-05");
-> ' February '
Quarter (date)
Return date is the quarter ordinal of a year
Mysql> Select quarter (' 98-04-01 ');
-> 2
WEEK (Date,first)
Returns date is the week ordinal of a year (first default 0,first value 1 means Monday is the beginning of the week, 0 starts in Sunday)
Mysql> Select WEEK (' 1998-02-20 ');
-> 7
Mysql> Select WEEK (' 1998-02-20 ', 0);
-> 7
Mysql> Select WEEK (' 1998-02-20 ', 1);
-> 8
Year (date)
Returns the year of date (range from 1000 to 9999)
Mysql> Select year (' 98-02-03 ');
-> 1998
HOUR (Time)
The number of hours to return time (range 0 to 23)
Mysql> Select HOUR (' 10:05:03 ');
-> 10
MINUTE (Time)
Returns the number of minutes in time (range 0 to 59)
Mysql> Select MINUTE (' 98-02-03 10:05:03 ');
-> 5
SECOND (Time)
Returns the number of seconds in time (range is 0 to 59)
Mysql> Select SECOND (' 10:05:03 ');
-> 3
Period_add (P,n)
Increase n months to time P and return (P's format yymm or YYYYMM)
Mysql> Select Period_add (9801,2);
-> 199803
Period_diff (P1,P2)
Returns the number of months between periods P1 and P2 (P1 and P2 formats yymm or YYYYMM)
Mysql> Select Period_diff (9802,199703);

-> 11

Date_add (Date,interval expr type)
Date_sub (Date,interval expr type)
Adddate (Date,interval expr type)
Subdate (Date,interval expr type)
Add and subtract a date time
(Adddate () and subdate () are synonyms for Date_add () and Date_sub (), and you can also use operators and-instead of 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.