타임스탬프 함수

타임스탬프 함수

이름 설명
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 TIMESTAMP1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 변환합니다.
TIMESTAMP_TO_UNIX_MILLIS TIMESTAMP1970-01-01 00:00:00 UTC 이후의 밀리초 수로 변환합니다.
TIMESTAMP_TO_UNIX_SECONDS TIMESTAMP1970-01-01 00:00:00 UTC 이후의 초 수로 변환합니다.

CURRENT_TIMESTAMP

구문:

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 'second' 입력하지 않음 2001-01-01 10:20:30 UTC
1997-05-31 04:30:30 UTC 'day' 입력하지 않음 1997-05-31 00:00:00 UTC
1997-05-31 04:30:30 UTC 'day' 'America/Los_Angeles' 1997-05-30 07:00:00 UTC
2001-03-16 04:00:00 UTC 'week(friday)' 입력하지 않음 2001-03-16 00:00:00 UTC
2001-03-23 04:00:00 UTC 'week(friday)' 'America/Los_Angeles' 2001-03-23 17:00:00 UTC
2026-01-24 20:00:00 UTC 'month' '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로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.

예:

input unix_micros_to_timestamp(input)
0L 1970-01-01 00:00:00 UTC
400123456L 1970-01-01 00:06:40.123456 UTC
-1000000L 1969-12-31 23:59:59 UTC

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString")
  )
);
Swift
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로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.

예:

input unix_millis_to_timestamp(input)
0L 1970-01-01 00:00:00 UTC
4000123L 1970-01-01 01:06:40.123 UTC
-1000000L 1969-12-31 23:43:20 UTC

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMillis").unixMillisToTimestamp().as("createdAtString")
  )
);
Swift
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로 변환합니다. input을 유효한 TIMESTAMP로 변환할 수 없는 경우 error가 발생합니다.

예:

input unix_seconds_to_timestamp(input)
0L 1970-01-01 00:00:00 UTC
60L 1970-01-01 00:01:00 UTC
-300L 1969-12-31 23:55:00 UTC

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString")
  )
);
Swift
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

설명:

timestamp에서 unitamount를 추가합니다. 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 'minute' 2L 2025-02-20 00:02:00 UTC
2025-02-20 00:00:00 UTC 'hour' -4L 2025-02-19 20:00:00 UTC
2025-02-20 00:00:00 UTC 'day' 5L 2025-02-25 00:00:00 UTC

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("createdAt").timestampAdd("day", 3653).as("expiresAt")
  )
);
Swift
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

설명:

timestamp에서 unitamount를 뺍니다. 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 'minute' 40L 2026-07-03 23:20:00 UTC
2026-07-04 00:00:00 UTC 'hour' -24L 2026-07-05 00:00:00 UTC
2026-07-04 00:00:00 UTC 'day' 3L 2026-07-01 00:00:00 UTC

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp")
  )
);
Swift
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

설명:

input1970-01-01 00:00:00 UTC 이후의 마이크로초 수로 변환합니다. 마이크로초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.

예:

input timestamp_to_unix_micros(input)
1970-01-01 00:00:00 UTC 0L
1970-01-01 00:06:40.123456 UTC 400123456L
1969-12-31 23:59:59 UTC -1000000L

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMicros().as("unixMicros")
  )
);
Swift
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

설명:

input1970-01-01 00:00:00 UTC 이후의 밀리초 수로 변환합니다. 밀리초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.

예:

input timestamp_to_unix_millis(input)
1970-01-01 00:00:00 UTC 0L
1970-01-01 01:06:40.123 UTC 4000123L
1969-12-31 23:43:20 -1000000L

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMillis().as("unixMillis")
  )
);
Swift
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()
)

TIMESTAMP_TO_UNIX_SECONDS

구문:

timestamp_to_unix_seconds(input: TIMESTAMP) -> INT64

설명:

input1970-01-01 00:00:00 UTC 이후의 초 수로 변환합니다. 초 시작 부분으로 반내림하여 높은 정밀도 수준을 자릅니다.

예:

input timestamp_to_unix_seconds(input)
1970-01-01 00:00:00 UTC 0L
1970-01-01 00:01:00 UTC 60L
1969-12-31 23:55:00 UTC -300L

Web

const result = await execute(db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixSeconds().as("unixSeconds")
  )
);
Swift
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()
)