MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB SECOND() Function



The MariaDB SECOND() function returns the second portion of a given time or datetime value. It can be between 0 to 59.

Syntax

SECOND(datetime)

Parameters

datetime Required. Specify a time or datetime value from which to extract the second.

Return Value

Returns the second part of a given time or datetime value.

Example 1:

The example below shows the usage of SECOND() function.

SELECT SECOND('2018-08-18');
Result: 0

SELECT SECOND('2018-08-18 10:38:32');
Result: 32

SELECT SECOND('2018-08-18 10:38:32.000004');
Result: 32

SELECT SECOND("838:38:42");
Result: 42

SELECT SECOND(CURDATE());
Result: 54

Example 2:

Consider a database table called Orders with the following records:

OrderQuantityPriceOrderTime
1001.582017-08-18 10:38:42
1201.612018-03-23 07:14:16
1251.782018-09-12 05:25:56
501.802019-01-16 11:52:05
2001.722020-02-06 09:31:34

The statement given below can be used to get the second portion of records of column OrderTime:

SELECT *, SECOND(OrderTime) AS SECOND_Value FROM Orders;

This will produce the result as shown below:

OrderQuantityPriceOrderTimeSECOND_Value
1001.582017-08-18 10:38:4242
1201.612018-03-23 07:14:1616
1251.782018-09-12 05:25:5656
501.802019-01-16 11:52:055
2001.722020-02-06 09:31:3434

❮ MariaDB Functions