SECOND() Function in MySQL

SECOND() function in MySQL is used to return the second portion of a specified time or date-time value. The first parameter in this function will be the date/Date Time. This function returns the seconds from the given date value. The return value (seconds) will be in the range of 0 to 59. In this function, we will pass the date value in it and it will return the second of the date as result. For example, if the specified time is β€œ09:12:23”, then this function will return β€œ23” as a result.

Features:

  • This function is used to find the second portion of a specified time or date time value.
  • This function accepts a single parameter.
  • The accepted parameter will be the date/date time.
  • This function returns the seconds value which ranges from 0 to 59.

Syntax:

SECOND(date_value)

Parameter: This method accepts a parameter illustrated below:

date_value: Specified time or date time value to extract the second.

Returns: It returns the second part for a specified time or date time value.

Application: This function is used to return the second part for a specified time or date time values.

Example 1: Getting the result β€œ12” from the specified date-time β€œ2020-11-24 09:32:12”.

SELECT SECOND("2020-11-24 09:32:12");

Output:

12

Example 2: Getting the result β€œ30” from the specified date-time β€œ2021-12-20 02:24:30”.

SELECT SECOND("2021-12-20 02:24:30");

Output :

30

Example 3: Getting the result β€œ23β€³ from the specified time β€œ06:12:23”.

SELECT SECOND("06:11:23");

Output:

23

Example 4: Getting the result β€œ59” from the specified time β€œ23:12:59”.

SELECT SECOND("23:12:59");

Output:

59

Example 5: Getting the result β€œ16” from the datetime. The parameter datetime value β€œ16β€³ has been returned by the function β€œPOWER(2, 4)” and the SECOND() function takes this value β€œ16” as the parameter and returns the same value β€œ16” as the second value.

SELECT SECOND(POWER(2, 4));

Output:

16

Example 6: Getting the result from the current time. This will return the second portion of the current system time. For example, if the current system time is β€œ06:12:23”, then it will return β€œ23” as a result.

SELECT SECOND(CURTIME());

Output :

23

Example 7: Getting the result from the system date. This will return the second portion from the system date. For example, if the system date is β€œ2021-02-05 12:41:26”, then it will return β€œ26” as a result.

SELECT SECOND(SYSDATE());

Output:

26