MySQL Second Function

MySQL Second is one of the Date Functions that returns the Seconds value from a given time. This Second method returns integer values ranging from 0 to 59. The basic syntax of the MySQL Second Function is as shown below:

SECOND(Time or expression);

MySQL Second function Example

The below-shown queries help you understand the use of this Second function. In this instance, we return the Second value from the different time expressions and Datetime expressions.

SELECT SECOND('10:22:45');

SELECT SECOND('2019-02-05 10:20:12');

SELECT SECOND('2019-02-05 10:20:59.112352');
Second Example 1

In this Date method example, we return the Seconds value from the current date and time returned by the Now(), UTC_TIME, and UTC_TIMESTAMP functions.

SELECT NOW(), SECOND(NOW());

SELECT UTC_TIME(), SECOND(UTC_TIME());

SELECT UTC_TIMESTAMP(), SECOND(UTC_TIMESTAMP());
MySQL Second Function example 2

In this MySQL function example, we are trying to return the seconds value from the String DateTime format and HHMMSS formats. Within the last MySQL statement, we used the zero hour part as an input.

SELECT NOW(), SECOND(NOW() + 10); 

SELECT SECOND(101235);

SELECT SECOND('00:12:22');
Second example 3

Second Example 3

This example shows you how to use this one on table data. Here, we are returning the seconds value from the Hire Date column.

SELECT EmpID,
       FirstName,
       LastName,
       Occupation,
       YearlyIncome,
       Sales,
       HireDate,
       SECOND(HireDate)
 FROM customer;
MySQL Second Function 4