Example
Return a time value based on a specified seconds value:
SELECT SEC_TO_TIME(1);
Definition and Usage
The SEC_TO_TIME() function returns a time value (in format HH:MM:SS) based on the specified seconds.
Syntax
SEC_TO_TIME(seconds)
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)
Add a specified number of months to a period:
SELECT PERIOD_ADD(201703, 5);
The PERIOD_ADD() function adds a specified number of months to a period.
The PERIOD_ADD() function will return the result formatted as YYYYMM.
PERIOD_ADD(period, number)
Return current date and time:
SELECT NOW();
The NOW() 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.uuuuuu (numeric).
NOW()
Return the name of the month for a date:
SELECT MONTHNAME("2017-06-15");
The MONTHNAME() function returns the name of the month for a given date.
MONTHNAME(date)
Return the month part of a date:
SELECT MONTH("2017-06-15");
The MONTH() function returns the month part for a given date (a number from 1 to 12).
MONTH(date)
Return the minute part of a datetime value:
SELECT MINUTE("2017-06-20 09:34:00");
The MINUTE() function returns the minute part of a time/datetime (from 0 to 59).
MINUTE(datetime)
Return the microsecond part of a datetime:
SELECT MICROSECOND("2017-06-20 09:34:00.000023");
The MICROSECOND() function returns the microsecond part of a time/datetime (from 0 to 999999). Continue reading MySQL MICROSECOND Function