shorttime_to_seconds

NAME

shorttime_to_seconds(): Return the number of seconds represented by the given short form

TYPE

Function

DESCRIPTION

This function evaluates the number of seconds expressed by the given input. Input is expected to be in short time format (see following).

The function returns NULL on invalid input: any input which is not in short-time format, including plain numbers (to emphasize: the input '12' is invalid)

SYNOPSIS

shorttime_to_seconds(shorttime VARCHAR(16) CHARSET ascii)
  RETURNS INT UNSIGNED 

Input:

  • shorttime: short time format, denoted by a number followed by a unit. Valid units are:
    • s (seconds), e.g. '30s' makes for 30 seconds.
    • m (minutes), e.g. '3m' makes for 3 minutes, resulting with 180 seconds.
    • h (hours), e.g. '2h' makes for 2 hours, resulting with 7200 seconds.

EXAMPLES

Parse '2h', making for 2 hours:

mysql> SELECT shorttime_to_seconds('2h') as seconds;
+---------+
| seconds |
+---------+
|    7200 |
+---------+

Fail on invalid input:

mysql> SELECT shorttime_to_seconds('2') as seconds;
+---------+
| seconds |
+---------+
|    NULL |
+---------+

ENVIRONMENT

MySQL 5.1 or newer

AUTHOR

Shlomi Noach
 
common_schema documentation