Функции временных меток
| Имя | Описание |
CURRENT_TIMESTAMP | Генерирует TIMESTAMP соответствующую времени запроса. |
TIMESTAMP_TRUNC | Усекает TIMESTAMP до заданного значения. |
UNIX_MICROS_TO_TIMESTAMP | Преобразует количество микросекунд с 1970-01-01 00:00:00 UTC в TIMESTAMP |
UNIX_MILLIS_TO_TIMESTAMP | Преобразует количество миллисекунд с 1970-01-01 00:00:00 UTC в TIMESTAMP |
UNIX_SECONDS_TO_TIMESTAMP | Преобразует количество секунд с 1970-01-01 00:00:00 UTC в TIMESTAMP |
TIMESTAMP_ADD | Добавляет временной интервал к TIMESTAMP |
TIMESTAMP_SUB | Вычитает временной интервал из TIMESTAMP |
TIMESTAMP_TO_UNIX_MICROS | Преобразует TIMESTAMP в количество микросекунд с 1970-01-01 00:00:00 UTC |
TIMESTAMP_TO_UNIX_MILLIS | Преобразует TIMESTAMP в количество миллисекунд с 1970-01-01 00:00:00 UTC |
TIMESTAMP_TO_UNIX_SECONDS | Преобразует TIMESTAMP в количество секунд с 1970-01-01 00:00:00 UTC |
ТЕКУЩАЯ_ВРЕМЕННАЯ_МЕТКА
Синтаксис:
current_timestamp() -> TIMESTAMP
Описание:
Получает метку времени в начале input времени запроса (интерпретируется как количество микросекунд с 1970-01-01 00:00:00 UTC ).
Это значение стабильно в рамках одного запроса и всегда будет возвращать одно и то же значение при многократном вызове.
TIMESTAMP_TRUNC
Синтаксис:
timestamp_trunc(timestamp: TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP
Описание:
Усекает временную метку до заданной точности.
Аргумент granularity должен быть строкой и одним из следующих значений:
-
microsecond -
millisecond -
second -
minute -
hour -
day -
week -
week([weekday]) -
month -
quarter -
year -
isoyear
Если указан аргумент timezone , обрезка будет производиться на основе календарных границ заданного часового пояса (например, обрезка дня будет производиться до полуночи в заданном часовом поясе). При обрезке будет учитываться переход на летнее время.
Если timezone не указан, обрезка будет производиться на основе границ календаря UTC .
Аргумент timezone должен представлять собой строковое значение часового пояса из базы данных tz, например, America/New_York . Также можно использовать пользовательское смещение времени, указав смещение относительно GMT .
Примеры:
timestamp | granularity | timezone | timestamp_trunc(timestamp, granularity, timezone) |
|---|---|---|---|
| 2000-01-01 10:20:30:123456 UTC | "второй" | Не предоставлено | 2001-01-01 10:20:30 UTC |
| 1997-05-31 04:30:30 UTC | "день" | Не предоставлено | 1997-05-31 00:00:00 UTC |
| 1997-05-31 04:30:30 UTC | "день" | "Америка/Лос-Анджелес" | 1997-05-30 07:00:00 UTC |
| 2001-03-16 04:00:00 UTC | "неделя (пятница) | Не предоставлено | 2001-03-16 00:00:00 UTC |
| 2001-03-23 04:00:00 UTC | "неделя (пятница) | "Америка/Лос-Анджелес" | 2001-03-23 17:00:00 UTC |
| 2026-01-24 20:00:00 UTC | "месяц" | "GMT+06:32:43" | 2026-01-01T06:32:43 UTC |
UNIX_MICROS_TO_TIMESTAMP
Синтаксис:
unix_micros_to_timestamp(input: INT64) -> TIMESTAMP
Описание:
Преобразует input (интерпретируемые как количество микросекунд с 1970-01-01 00:00:00 UTC ) в TIMESTAMP ). Выбрасывает error , если input не могут быть преобразованы в допустимую TIMESTAMP .
Примеры:
input | unix_micros_to_timestamp(input) |
|---|---|
| 0 л | 1970-01-01 00:00:00 UTC |
| 400123456L | 1970-01-01 00:06:40.123456 UTC |
| -1000000 л | 1969-12-31 23:59:59 UTC |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtMicros").unixMicrosToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtMicros") .unix_micros_to_timestamp() .as_("createdAtString") ) .execute() )
UNIX_MILLIS_TO_TIMESTAMP
Синтаксис:
unix_millis_to_timestamp(input: INT64) -> TIMESTAMP
Описание:
Преобразует input (интерпретируемые как количество миллисекунд с 1970-01-01 00:00:00 UTC ) в тип TIMESTAMP . Выбрасывает error , если input не могут быть преобразованы в допустимый тип TIMESTAMP .
Примеры:
input | unix_millis_to_timestamp(input) |
|---|---|
| 0 л | 1970-01-01 00:00:00 UTC |
| 4000123L | 1970-01-01 01:06:40.123 UTC |
| -1000000 л | 1969-12-31 23:43:20 UTC |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().as("createdAtString") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtMillis").unixMillisToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtMillis").unixMillisToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtMillis") .unix_millis_to_timestamp() .as_("createdAtString") ) .execute() )
UNIX_SECONDS_TO_TIMESTAMP
Синтаксис:
unix_seconds_to_timestamp(input: INT64) -> TIMESTAMP
Описание:
Преобразует input (интерпретируемые как количество секунд с 1970-01-01 00:00:00 UTC ) в тип TIMESTAMP . Выбрасывает error , если input не могут быть преобразованы в допустимый тип TIMESTAMP .
Примеры:
input | unix_seconds_to_timestamp(input) |
|---|---|
| 0 л | 1970-01-01 00:00:00 UTC |
| 60 л | 1970-01-01 00:01:00 UTC |
| -300 л | 1969-12-31 23:55:00 UTC |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAtSeconds").unixSecondsToTimestamp().alias("createdAtString") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("createdAtSeconds") .unix_seconds_to_timestamp() .as_("createdAtString") ) .execute() )
TIMESTAMP_ADD
Синтаксис:
timestamp_add(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
Описание:
Добавляет amount unit из timestamp . Аргумент amount может быть отрицательным, в этом случае он эквивалентен TIMESTAMP_SUB .
Аргумент unit должен быть строкой и содержать одно из следующих значений:
-
microsecond -
millisecond -
second -
minute -
hour -
day
Вызывает ошибку, если полученная метка времени не укладывается в диапазон TIMESTAMP .
Примеры:
timestamp | unit | amount | timestamp_add(timestamp, unit, amount) |
|---|---|---|---|
| 2025-02-20 00:00:00 UTC | "минута" | 2 л | 2025-02-20 00:02:00 UTC |
| 2025-02-20 00:00:00 UTC | "час" | -4 л | 2025-02-19 20:00:00 UTC |
| 2025-02-20 00:00:00 UTC | "день" | 5 л | 2025-02-25 00:00:00 UTC |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("createdAt").timestampAdd("day", 3653).as("expiresAt") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("createdAt").timestampAdd(3653, .day).as("expiresAt") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("createdAt") .timestampAdd("day", 3653) .alias("expiresAt") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("createdAt").timestampAdd("day", 3653).alias("expiresAt") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("createdAt").timestamp_add("day", 3653).as_("expiresAt")) .execute() )
TIMESTAMP_SUB
Синтаксис:
timestamp_sub(timestamp: TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
Описание:
Вычитает amount unit из timestamp . Аргумент amount может быть отрицательным, в этом случае он эквивалентен TIMESTAMP_ADD .
Аргумент unit должен быть строкой и содержать одно из следующих значений:
-
microsecond -
millisecond -
second -
minute -
hour -
day
Вызывает ошибку, если полученная метка времени не укладывается в диапазон TIMESTAMP .
Примеры:
timestamp | unit | amount | timestamp_sub(timestamp, unit, amount) |
|---|---|---|---|
| 2026-07-04 00:00:00 UTC | "минута" | 40 л | 2026-07-03 23:20:00 UTC |
| 2026-07-04 00:00:00 UTC | "час" | -24 л | 2026-07-05 00:00:00 UTC |
| 2026-07-04 00:00:00 UTC | "день" | 3 л | 2026-07-01 00:00:00 UTC |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("expiresAt").timestampSubtract(14, .day).as("sendWarningTimestamp") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("expiresAt") .timestampSubtract("day", 14) .alias("sendWarningTimestamp") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("expiresAt").timestampSubtract("day", 14).alias("sendWarningTimestamp") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select( Field.of("expiresAt") .timestamp_subtract("day", 14) .as_("sendWarningTimestamp") ) .execute() )
TIMESTAMP_TO_UNIX_MICROS
Синтаксис:
timestamp_to_unix_micros(input: TIMESTAMP) -> INT64
Описание:
Преобразует input в количество микросекунд с 1970-01-01 00:00:00 UTC . Более высокие уровни точности округляются в меньшую сторону до начала микросекунды.
Примеры:
input | timestamp_to_unix_micros(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0 л |
| 1970-01-01 00:06:40.123456 UTC | 400123456L |
| 1969-12-31 23:59:59 UTC | -1000000 л |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().as("unixMicros") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixMicros().as("unixMicros") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().alias("unixMicros") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMicros().alias("unixMicros") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_micros().as_("unixMicros")) .execute() )
TIMESTAMP_TO_UNIX_MILLIS
Синтаксис:
timestamp_to_unix_millis(input: TIMESTAMP) -> INT64
Описание:
Преобразует input в количество миллисекунд с 1970-01-01 00:00:00 UTC . Более высокие уровни точности округляются в меньшую сторону до начала миллисекунды.
Примеры:
input | timestamp_to_unix_millis(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0 л |
| 1970-01-01 01:06:40.123 UTC | 4000123L |
| 1969-12-31 23:43:20 | -1000000 л |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().as("unixMillis") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixMillis().as("unixMillis") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().alias("unixMillis") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixMillis().alias("unixMillis") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_millis().as_("unixMillis")) .execute() )
ОТМЕТКА ВРЕМЕНИ В СЕКУНДЫ UNIX
Синтаксис:
timestamp_to_unix_seconds(input: TIMESTAMP) -> INT64
Описание:
Преобразует input в количество секунд с 1970-01-01 00:00:00 UTC . Более высокие уровни точности округляются до начала секунды.
Примеры:
input | timestamp_to_unix_seconds(input) |
|---|---|
| 1970-01-01 00:00:00 UTC | 0 л |
| 1970-01-01 00:01:00 UTC | 60 л |
| 1969-12-31 23:55:00 UTC | -300 л |
Web
const result = await execute(db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().as("unixSeconds") ) );
Быстрый
let result = try await db.pipeline() .collection("documents") .select([ Field("dateString").timestampToUnixSeconds().as("unixSeconds") ]) .execute()
Kotlin
val result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().alias("unixSeconds") ) .execute()
Java
Task<Pipeline.Snapshot> result = db.pipeline() .collection("documents") .select( field("dateString").timestampToUnixSeconds().alias("unixSeconds") ) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import Field result = ( client.pipeline() .collection("documents") .select(Field.of("dateString").timestamp_to_unix_seconds().as_("unixSeconds")) .execute() )