MySQL Modify Time function adddate (date, INTERVAL expr unit)

Source: Internet
Author: User

MySQL Modify time function:

1. Adddate (date,interval expr unit) INTERVAL represents the time interval :


SELECT now (); 2018-06-20 15:00:00--Current time
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-60 SECOND) as time; 2018-06-20 14:59:00--minus 60 seconds
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-1 MINUTE) as time; 2018-06-20 14:59:00--minus 1 minutes
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-1 HOUR) as time; 2018-06-20 14:00:00--minus 1 hours
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-1 Day) as time; 2018-06-19 15:00:00-minus 1 days
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-1 MONTH) as time; 2018-05-20 15:00:00--minus 1 months
SELECT adddate (' 2018-06-20 15:00:00 ', INTERVAL-1 year) as time; 2017-06-20 15:00:00--minus 1 years

Link: 55259766 (mysql date and character conversion method )


2. Date_format (date, '%y-%m-%d ') ———— to_char () in –>oracle;
3. Str_to_date (date, '%y-%m-%d ') ———— to_date () in –>oracle;

%Y: Represents a 4-digit year
%y: Represents the year of 2

%m: Represents the month, in the form of (01 ... 12)
%c: Represents the month in the format of (1 ... 12)

%d: Represents the number of days in the month in the format (00 ...). 31)
%e: Represents the number of days in the month in the format (0 ...). 31)

%H: Represents the hour, in the form of (00 ... 23)
%k: Represents the hour, in the form of (0 ... 23)
%h: Represents the hour, in the form of (01 ... 12)
%I: Represents the hour, in the form of (01 ... 12)
%l: Represents the hour, in the form of (1 ... 12)

%i: Represents minutes, in the form of (00 ... 59) "Only this one represents minutes, the uppercase I does not represent minutes for the hour"

%r: Represents the time, in the format of 12 hours (Hh:mm:ss [ap]m)
%T: Represents the time, in the format of 24 hours (HH:MM:SS)

%s: represents seconds in the format (00 ...). 59)
%s: represents seconds in the format (00 ...). 59)


MySQL Modify Time function adddate (date, INTERVAL expr unit)

Related Article

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.