MySQL Time processing

Source: Internet
Author: User

Many times, we in the MySQL database query when we want to deal with time, such as formatting or other operations, this way to avoid the re-processing, and MySQL has a lot of time to deal with the function, today simple to do a small summary, for everyone to reference.

First on the time of the comparison function, this people refer to my other article, here no longer tell: http://blog.csdn.net/fanxl10/article/details/44172569

If we want to increase or decrease the processing time, we can use the Date_add () function, passed two parameters, the first parameter is to change the time, the second parameter is to change the value, for example, we want to increase the day, then the parameter is: INTERVAL 1 day, if you want to reduce the number of days, Then the parameter is INTERVAL-1 day, passing in a negative value, then if we want to add one months, that parameter is interval 1 month, and so on, the increase is interval 1 year, add one hours is interval 1 HOUR , here presumably everyone should understand how to use it, see the example below:

Isolate start time and add one day:

SELECT START, Date_add (START, INTERVAL 1 day) as Addstartfrom ts_tickeywhere id= ' 373 '

Find the results as follows:


If we want to increase the start time of the database by one day, it is also very simple:

UPDATE ts_tickey SET start=date_add (START, INTERVAL 1 day) WHERE id= ' 373 '
Other usage let's try it on your own, there's basically nothing to say.


The other one is the MySQL time Format function date_format (), also, the transmission of two parameters, the first parameter is to format the time, the second parameter formatted format, such as:

Date_format (A.start, '%y-%m-%d ') as Start
This is the format of start time into YYYY-MM-DD format.

Or it can be formatted into seconds and minutes:

Date_format (a.uploaddate, '%h:%i:%s ')



MySQL Time processing

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.