getTimeBefore

Get a timestamp a fixed duration before another time.

Available in read and write scripts. Part of the virtual tag expression reference.

Returns a timestamp a fixed duration before another — handy for building history ranges.

getTimeBefore(duration: string, time: number): number;

Parameters

  • duration — how far back, as a number and unit, e.g. "30m", "1h", "7d". Units are s (seconds), m (minutes), h (hours), d (days), w (weeks).
  • time — the Unix timestamp, in seconds, to subtract from.

Return value

The earlier timestamp, in seconds.

Example

// One hour before now
getTimeBefore("1h", getCurrentTime());