Sunday, December 22, 2024

MySQL SECOND() Function

 The SECOND() function in MySQL is used to extract the second part of a time or datetime value. It returns the second value as an integer between 0 and 59.

Syntax:

SECOND(time_value)
  • time_value: This is a valid TIME, DATETIME, or TIMESTAMP value from which you want to extract the second.

Example 1: Extract the second from a TIME value

SELECT SECOND('12:34:56');

Output: 56

Example 2: Extract the second from a DATETIME value

SELECT SECOND('2024-12-23 14:35:45');

Output: 45

Example 3: Extract the second from the current time

SELECT SECOND(NOW());

This will return the current second from the current DATETIME value.

Note:

  • If the input value is NULL, the result will also be NULL.

No comments:

Post a Comment