Skip to content
Related Articles
Open in App
Not now

Related Articles

TIME and TIME_TO_SEC Function in MariaDB

Improve Article
Save Article
  • Last Updated : 14 Dec, 2020
Improve Article
Save Article

1. TIME Function :
In MariaDB, The TIME Function returns the time portion of a DateTime expression. In this function, the first parameter will be the DateTime. This function returns the time given a DateTime. In this function, we will pass the DateTime expression in it and it will return the time of the DateTime expression as result. if the expression is not a time or a DateTime value, the TIME function will return ’00:00:00′. If the expression is NULL, the TIME function will return NULL.

Syntax :

TIME( expression )

Parameter :

  • Datetime expression –The time value from which the time should be extracted.

Return :
It will return the time portion of a DateTime expression.

Example-1 :

SELECT TIME('2020-10-16 06:18:01.000001');

Output :

'06:18:01.000001'

Example-2 :

SELECT TIME('10:35:05');

Output :

10:35:05

Example-3 :

SELECT TIME(NULL);

Output :

NULL

2. TIME_TO_SEC Function :
In MariaDB, TIME_TO_SEC Function is used to convert a time value into numeric seconds. In this function, the first parameter will be time. And this function will return The time value to convert to numeric seconds. It works opposite to the SEC_TO_TIME function.

Syntax :

TIME_TO_SEC( time )

Parameters :

  • Time –The time value to convert to numeric seconds.

Return :
Return the time in numeric seconds.

Example-1 :

SELECT TIME_TO_SEC('00:00:02');

Output :

2

Example-2 :

SELECT TIME_TO_SEC('00:00:01.999999');

Output :

1

Example-3 :

SELECT TIME_TO_SEC('-12:30:59');

Output :

-45059

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!