Skip to content

DurationParse

imshooter edited this page Nov 26, 2026 · 1 revision

Read a duration such as 1h 30m or 2d12h.

native bool:DurationParse(const string[], &Milliseconds:output);

Parameters

Parameter Description
const string[] The text.
&Milliseconds:output The duration read.

Returns

  • true when it was read.
  • false when the text is not a duration or is longer than 24 days. output is left as it was.

Remarks

Numbers are each followed by a unit: ms, s, m, h, d, w, or y for a year of 365 days. Units take any case, and spaces may stand anywhere between them. A longer duration fits DurationParseSeconds.

Example

stock MutePlayer(playerid, const text[]) {
    new
        Milliseconds:duration
    ;

    if (!DurationParse(text, duration)) {
        return SendClientMessage(playerid, -1, "Write the time as 10m or 1h 30m.");
    }

    SetTimerEx("OnMuteEnd", _:duration, false, "i", playerid);

    return 1;
}

Related

Clone this wiki locally