MySQL time function _ MySQL

Source: Internet
Author: User
Tags month name
MySQL's time function bitsCN. comCURDATE () or CURRENT_DATE () returns the current date, in YYYY-MM-DD or YYYYMMDD format. Contains only the year, month, and day
select curdate()+0;
Result: 20140214
select curdate()+1;
Result: 20140215
CURTIME () or CURRENT_TIME () returns the current time, including the hour, minute, and second.
NOW () returns the current time, including the date and time
UTC_DATE function returns UTC time, Beijing time = UTC time + 8 hours
UNIX_TIMESTAMP (), UNIX_TIMESTAMP (date) If no parameter is called, a Unix timestamp ('2017-01-01 00:00:00 'seconds after GMT) is returned as an unsigned integer. If you use date to call UNIX_TIMESTAMP (), it will return the parameter value in the form of the number of seconds after '2017-01-01 00:00:00 'GMT. Date can be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the YYMMDD or YYYMMDD format of the local time. [SQL]View plaincopy Mysql> % 20 SELECT % 20UNIX_TIMESTAMP ();
  • -> % 20882226357
  • Mysql> % 20 SELECT % 20UNIX_TIMESTAMP ('2017-10-1997 ');
  • -> % 20875996580 FROM_UNIXTIME () % 20 returns the date value of the unix timestamp. Mysql> SELECT % 20FROM_UNIXTIME (875996580); % 20% 20% 20% 20-> '2017-10-20%' TO_DAYS (date) % 20 given a date, % 20 returns a day % 20 (from the year 0 days % 20 ). % 20 [SQL]% 20 view % 20 plaincopy
    1. Mysql> SELECT TO_DAYS (950501 );
    2. -> 728779
    3. Mysql> SELECT TO_DAYS ('2017-10-07 ');

    -> 729669
    The DATEDIFF function datediff (date1, date2) is used to calculate the number of days between two dates.
    DATE_ADD function or ADDDATE function date_add (date, interval expr type): return the date that differs from the given date in the interval period.
    DATE_SUB function or SUBDATE function date_sub (date, interval expr type): returns the date of expr type earlier than the given date.
    MySQL allows punctuation separators in any expr format. The recommended delimiter is displayed in the table. If the date parameter is a DATE value, and your calculation only includes the YEAR, MONTH, and DAY sections (that is, there is no time section), the result is a DATE value. Otherwise, the result is a DATETIME Value. If the expression at the other end is a date or DateTime Value, INTERVAL expr type is only allowed at both ends of the + operator. For the-operator, INTERVAL expr type is only allowed on the right side, because it is meaningless to extract a date or datetime value from a time INTERVAL. (See the example below ).
    The EXTRACT () function is used to return a separate part of a date or time, such as year, month, day, hour, or minute.

    DATE_FORMAT (date, format)
    Format the date value based on the format string (a flag is available in the format string:
    % M month name (January ...... December)
    % W name of the week (Sunday ...... Saturday)
    % D indicates the date of the month with an English prefix (1st, 2nd, 3rd, and so on .)
    % Y year, number, 4 digits
    % Y year, number, 2 digits
    % A abbreviated name of the week (Sun ...... Sat)
    % D number of days in the month (00 ...... 31)
    % E number of days in the month (0 ...... 31)
    % M month, number (01 ...... 12)
    % C month, number (1 ...... 12)
    % B abbreviated month name (Jan ...... Dec)
    % J days in a year (001 ...... 366)
    % H Hour (00 ...... 23)
    % K hour (0 ...... 23)
    % H Hour (01 ...... 12)
    % I hour (01 ...... 12)
    % L hour (1 ...... 12)
    % I minute, number (00 ...... 59)
    % R time, 12 hours (hh: mm: ss [AP] M)
    % T time, 24 hours (hh: mm: ss)
    % S seconds (00 ...... 59)
    % S seconds (00 ...... 59)
    % P AM or PM
    % W days in a week (0 = Sunday ...... 6 = Saturday)
    % U week (0 ...... 52). Sunday is the first day of the week.
    % U week (0 ...... 52) Monday is the first day of the week.
    % Characters %)

    LAST_DAY () gets a date or date and time value, and returns the last day of the month.

    BitsCN.com

    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.