Skip to content
Related Articles

Related Articles

SECOND() Function in MySQL
  • Last Updated : 08 Feb, 2021

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :