Mysql time and date functions

Source: Internet
Author: User
Tags month name

Mysql time and date functions
Returns the date-related Now () | CURRENT_TIMESTAMP (); returns the current time to_days (date). returns the date value of the date value from the date of the year to date (not counted before January 1, 1582) convert to days date is the DATE type FROM_DAYS (N). It gives the number of days since the date DATE date value returned by the Western yuan 0 year (not before 1582) CURDATE () | CURRENT_DATE () | SYSDATE () current date // note the upper case weekDay (date) returns the day of the week of the specified date // The parameter is of the date type and cannot be in the time stamp format DAYOFWEEK (date) returns the day of the week of the specified date. // The parameter is of the date type. It cannot be the day of the Day of the specified date in the timestamp format. // The parameter is of the date type, it cannot be in the WEEK (date, first) format. // The parameter is in the date format. It cannot be in the timestamp format. The return date is the WEEK of the year (the default value of first is 0, first is used Value 1 indicates that Monday is the beginning of the week, and 0 starts from Sunday.) DAYOFMONTH (date) returns the number of the specified date in the current month. // The parameter is of the date type, it cannot be a timestamp format MONTH (date). Return the MONTH of the specified date. // The parameter is a date type. It cannot be a timestamp format MONTHNAME. Return the MONTH of date (returned by English name) // The parameter is of the date type. It cannot be a timestamp format QUARTER (date). Return the QUARTER where the date is the YEAR. // The parameter is of the date type and cannot be of the timestamp format YEAR (date) returns the date year // The parameter is of the Date type, and cannot be a timestamp format DATE_FORMAT (date, format); formatted date value select DATE_FORMAT (CURDATE () according to the format string (), '% W % M % y'); % W indicates the number of weeks in which the English language belongs. % M indicates the month in which the English belongs. % Y indicates the year in which the English belongs. select DATE_FORMAT (Now (),' % H: % I: % s '); % H returned hours % I returned minutes % s returned seconds select DATE_FORMAT (Now (), '% D % y % a % d % m % B % J ') % j days in a year (001 ...... 366) % B abbreviated month name (Jan ...... Dec) % m month, number (01 ...... 12) % d number of days in the month (00 ...... 31) % a abbreviated name of the Week (Sun ...... Sat) % y year, number, 2% D Date of the month with an English prefix (1st, 2nd, 3rd, and so on .) Select DATE_FORMAT (Now (), '% H % k % I % r % T % S % W'); % k hour (0 ...... 23) % l hour (1 ...... 12) % r time, 12 hours (hh: mm: ss [AP] M) % T time, 24 hours (hh: mm: ss) % S seconds (00 ...... 59) % w days in a week (0 = Sunday ...... 6 = Saturday) % Number of days in e month, number (0 ...... 31) % B abbreviated month name (Jan ...... Dec) % I hour (01 ...... 12) % s seconds (00 ...... 59) % p AM or PM % U Week (0 ...... 52), here Sunday is the first day of the week % u Week (0 ...... 52), here Monday is the first day of the week % characters % return time-related CURTIME () returns the current time HOUR (); returns the hours // The parameter is of the date type, the timestamp format cannot be MINUTE (time), and the number of minutes is returned. // The parameter is a date type. The timestamp format cannot be SECOND (time), and the number of seconds is returned. // The parameter is a date type, DATE_ADD (date, INTERVAL expr type) addition operation DATE_SUB (date, INTERVAL expr type) subtraction operation ADDDATE (date, INTERVAL expr type) add SUBDATE (date, INTERVAL expr type) subtraction addition and subtraction of Date and Time expr type second seconds minute minutes hour time hours day days month months year years MINUTE_SECOND MINUTES and SECONDS "MINUTES: SECONDS "HOUR_MINUTE hour and minute" HOURS: MINUTES "DAY_HOUR day and hour" days hours "YEAR_MONTH and month" YEARS-MONTHS "HOUR_SECOND hour, minute," HOURS: MINUTES: SECONDS "DAY_MINUTE day, hour, minute" days hours: MINUTES "DAY_SECOND day, hour, minute, second" days hours: MINUTES: SECONDS "select adddate (NOW (), INTERVAL 5 DAY); SELECT DATE_ADD (NOW (), INTERVAL 5 DAY); SELECT DATE_SUB (NOW (), INTERVAL 5 DAY); select subdate (NOW (), INTERVAL 5 DAY); UNIX_TIMESTAMP () UNIX_TIMESTAMP (Date); returns a Unix timestamp (seconds starting from '2017-01-01 00:00:00 'GMT, that is, the number of seconds FROM_UNIXTIME (UNIX_TIMESTAMP (). Based on the number of seconds, the FROM_UNIXTIME (unix_timestamp, format) character string of the specified date is returned for formatting) returns the number of seconds in which SEC_TO_TIME (seconds) is converted to the time value in the format of 'hh: MM: ss' or HHMMSS (the context of the returned value is a string or number)

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.