MySQL calculates a difference function for two datetime:
The first: theTimestampdiff function, which needs to pass in three parameters, the first being the type of comparison, can compare Frac_second, SECOND, MINUTE, HOUR, Day, WEEK, MONTH, quarter, or Year of several types, the second and third parameters are two times to compare, the comparison is the latter time minus the previous time, the specific usage is as follows:
SELECT Timestampdiff (Day, ' 2012-10-01 ', ' 2013-01-13 ');
The return result is 104, here is the difference between the days of two times;
SELECT Timestampdiff (MONTH, ' 2012-10-01 ', ' 2013-01-13 ');
The comparison here is the month of two times, the return result is 3;
The second method: The DateDiff function, passing in the two date function, compares the day days, the first parameter minus the second parameter's days value, the following is used as follows:
SELECT DATEDIFF (' 2013-01-13 ', ' 2012-10-01 ');
The returned result is also 104.
Another date function,
The now () function returns the date of the current time and seconds, such as:2008-12-29 16:25:46
The Curdate () function returns the month and day information: for example:2008-12-29
The Curtime () function returns the time-of-day information, such as:16:25:46
Also, if we want to format a date with a date that contains a month or two, you can use the DATE function, such as
DATE (now ()) returns the 2008-12-29
MySQL calculates a time difference function of two dates