MySQL TIMEDIFF Function

Example

Return the difference between two time expressions:

SELECT TIMEDIFF("13:10:11", "13:10:10");

Definition and Usage

The TIMEDIFF() function returns the difference between two time/datetime expressions.

Note: time1 and time2 should be in the same format, and the calculation is time1time2.

Syntax

TIMEDIFF(time1, time2)

Continue reading MySQL TIMEDIFF Function

MySQL TIME Function

Example

Extract the time part from a time expression:

SELECT TIME("19:30:10");

Definition and Usage

The TIME() function extracts the time part from a given time/datetime.

Note: This function returns “00:00:00” if expression is not a datetime/time, or NULL if expression is NULL.

Syntax

TIME(expression)

Continue reading MySQL TIME Function

MySQL PERIOD_DIFF Function

Example

Return the difference between two periods:

SELECT PERIOD_DIFF(201710, 201703);

Definition and Usage

The PERIOD_DIFF() function returns the difference between two periods. The result will be in months.

Note: period1 and period2 should be in the same format.

Syntax

PERIOD_DIFF(period1, period2)

Continue reading MySQL PERIOD_DIFF Function