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