Example
Format a time:
SELECT TIME_FORMAT("19:30:10", "%H %i %s");
Definition and Usage
The TIME_FORMAT() function formats a time by a specified format.
Syntax
TIME_FORMAT(time, format)
Format a time:
SELECT TIME_FORMAT("19:30:10", "%H %i %s");
The TIME_FORMAT() function formats a time by a specified format.
TIME_FORMAT(time, format)
Extract the time part from a time expression:
SELECT TIME("19:30:10");
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.
TIME(expression)
Return the current date and time:
SELECT SYSDATE();
The SYSDATE() function returns the current date and time.
Note: The date and time is returned as “YYYY-MM-DD HH:MM:SS” (string) or as YYYYMMDDHHMMSS (numeric).
SYSDATE()
Subtract 5.000001 seconds and return the datetime:
SELECT SUBTIME("2017-06-15 10:24:21.000004", "5.000001");
The SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.
SUBTIME(datetime, time_interval)
Subtract 10 days from a date and return the date:
SELECT SUBDATE("2017-06-15", INTERVAL 10 DAY);
The SUBDATE() function subtracts a time/date interval from a date and then returns the date.
SUBDATE(date, INTERVAL value unit)
OR:
SUBDATE(date, days)
Return a date based on a string and a format:
SELECT STR_TO_DATE("August 10 2017", "%M %d %Y");
The STR_TO_DATE() function returns a date based on a string and a format.
STR_TO_DATE(string, format)
Return a time value based on a specified seconds value:
SELECT SEC_TO_TIME(1);
The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds.
SEC_TO_TIME(seconds)
Return the seconds part of a datetime value:
SELECT SECOND("2017-06-20 09:34:00.000023");
The SECOND() function returns the seconds part of a time/datetime (from 0 to 59).
SECOND(datetime)
Return the quarter of the year for the date:
SELECT QUARTER("2017-06-15");
The QUARTER() function returns the quarter of the year for a given date value (a number from 1 to 4).
QUARTER(date)
Return the difference between two periods:
SELECT PERIOD_DIFF(201710, 201703);
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.
PERIOD_DIFF(period1, period2)