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