Skip to content
Lists & Helpers parseDuration

$parseDuration — Turns a written duration (1h30m, 2d, 45s) into a number of seconds

Turns a written duration (`1h30m`, `2d`, `45s`) into a number of seconds.

Syntax

$parseDuration[text;(unit)]

Parameters

  • text (text, required) — Parts made of a number and a unit: ms, s, m (minutes), h, d, w. A bare number is seconds.
  • unit (s or ms, optional) — Unit of the result. Default: s.

Return Value

  • number: empty when the text is not a valid duration.

Usage

$parseDuration[1h30m] → "5400"
$parseDuration[2d 4h] → "187200"
$parseDuration[banana] → ""

Important Notes

  • Base of every /timeout, /remind or /tempban command: check for an empty result.

Example

$sendMessage[$parseDuration[1h30m]]

Try it

Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.