Very many times. When we are querying the MySQL database, we want to process the time, for example, format or other operation, this way to avoid the processing. And MySQL also has a lot of time aspects of the processing function, today simple to do a small summary, for everyone to participate in the test.
First, the comparison function of time. This is another article that everyone has participated in, here no longer tells: http://blog.csdn.net/fanxl10/article/details/44172569
Let's say we want to add time or reduce processing. We can use the Date_add () function to pass in two parameters, the first argument is the time to change, the second is the value to change, for example, we want to add a day. So the number of participants is: INTERVAL 1 day, assuming that you want to reduce the number of days, then the argument is INTERVAL-1, passing in a negative value can be, that is to say we want to add one months, that is INTERVAL 1 month. And so on, adding a year is interval 1. Adding one hours is interval 1 HOUR. It must be clear how you should use it here. Here's a look at the example:
Check start time and add a day:
SELECT START, Date_add (START, INTERVAL 1 day) as Addstartfrom ts_tickeywhere id= ' 373 '
Find the results such as the following:
Suppose we want to add the start time of the database to the day. It's also very easy:
UPDATE ts_tickey SET start=date_add (START, INTERVAL 1 day) WHERE id= ' 373 '
Other use methods let's try it on our own. There's basically nothing to say.
The other one is the MySQL time Format function date_format (), as well, the transmission of two parameters. The first number of parameters is the time to format. The formatted format of the second parameter, for example:
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