Skip to content

extractTime

Description

Returns a specific unit of time extracted from a timestamp, such as the hour, minute, or second.

Note

  • Date units such as 'month' or 'week' start from 1, not 0.
  • Units smaller than minute return floating-point numbers; all others return integers.

Syntax

Like many functions in DataPrime, extractTime supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

extractTime(timestamp: timestamp, unit: dateunit | timeunit, tz?: string): number
(timestamp: timestamp).extractTime(unit: dateunit | timeunit, tz?: string): number

Arguments

NameTypeRequiredDescription
timestamptimestamptrueThe timestamp to extract from
unitdateunit | timeunittrueThe unit of time to extract, in short or long notation
tzstringfalseA valid time zone string (see Time Zone section for details)

Example

Use case 1: Find the hour in a specific time zone

Extract the hour of the day from a timestamp, adjusted to Tokyo time.

{
  "timestamp": 1728636298
}
choose extractTime($m.timestamp, 'h', 'Asia/Tokyo') as h
choose $m.timestamp.extractTime('h', 'Asia/Tokyo') as h

Output

{
  "h": 20
}