Hàm dấu thời gian

Hàm dấu thời gian

Tên Mô tả
CURRENT_TIMESTAMP Tạo TIMESTAMP tương ứng với thời gian yêu cầu.
TIMESTAMP_TRUNC Cắt bớt TIMESTAMP theo mức độ chi tiết nhất định.
UNIX_MICROS_TO_TIMESTAMP Chuyển đổi số micrô giây kể từ 1970-01-01 00:00:00 UTC thành TIMESTAMP
UNIX_MILLIS_TO_TIMESTAMP Chuyển đổi số mili giây kể từ 1970-01-01 00:00:00 UTC thành TIMESTAMP
UNIX_SECONDS_TO_TIMESTAMP Chuyển đổi số giây kể từ 1970-01-01 00:00:00 UTC thành TIMESTAMP
TIMESTAMP_ADD Thêm khoảng thời gian vào TIMESTAMP
TIMESTAMP_SUB Trừ một khoảng thời gian khỏi TIMESTAMP
TIMESTAMP_TO_UNIX_MICROS Chuyển đổi TIMESTAMP thành số micrô giây kể từ 1970-01-01 00:00:00 UTC
TIMESTAMP_TO_UNIX_MILLIS Chuyển đổi TIMESTAMP thành số mili giây kể từ 1970-01-01 00:00:00 UTC
TIMESTAMP_TO_UNIX_SECONDS Chuyển đổi TIMESTAMP thành số giây kể từ 1970-01-01 00:00:00 UTC
TIMESTAMP_DIFF Trả về số nguyên của các khoảng unit được chỉ định giữa hai TIMESTAMP.
TIMESTAMP_EXTRACT Trích xuất một part cụ thể (ví dụ: năm, tháng, ngày) từ một TIMESTAMP.

CURRENT_TIMESTAMP

Cú pháp:

current_timestamp() -> TIMESTAMP

Nội dung mô tả:

Lấy dấu thời gian khi bắt đầu thời gian yêu cầu input (được hiểu là số micrô giây kể từ 1970-01-01 00:00:00 UTC).

Giá trị này ổn định trong một truy vấn và sẽ luôn phân giải thành cùng một giá trị nếu được gọi nhiều lần.

TIMESTAMP_TRUNC

Cú pháp:

timestamp_trunc(timestamp: TIMESTAMP | BSON_TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP

Nội dung mô tả:

Cắt bớt dấu thời gian xuống một mức độ chi tiết nhất định.

Đối số granularity phải là một chuỗi và là một trong những giá trị sau:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • week
  • week([weekday])
  • month
  • quarter
  • year
  • isoyear

Nếu bạn cung cấp đối số timezone, thì việc cắt bớt sẽ dựa trên ranh giới lịch của múi giờ đã cho (ví dụ: việc cắt bớt ngày sẽ cắt bớt đến nửa đêm theo múi giờ đã cho). Việc cắt bớt sẽ tuân theo giờ mùa hè.

Nếu bạn không cung cấp timezone, thì việc cắt bớt sẽ dựa trên ranh giới lịch UTC.

Đối số timezone phải là chuỗi đại diện cho múi giờ trong cơ sở dữ liệu tz, ví dụ: America/New_York. Bạn cũng có thể sử dụng độ lệch thời gian tuỳ chỉnh bằng cách chỉ định độ lệch từ GMT.

Ví dụ:

timestamp granularity timezone timestamp_trunc(timestamp, granularity, timezone)
2000-01-01 10:20:30:123456 UTC "second" Không được cung cấp 2001-01-01 10:20:30 UTC
1997-05-31 04:30:30 UTC "ngày" Không được cung cấp 1997-05-31 00:00:00 UTC
1997-05-31 04:30:30 UTC "ngày" "America/Los_Angeles" 1997-05-30 07:00:00 UTC
2001-03-16 04:00:00 UTC "week(friday) Không được cung cấp 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
20:00:00 ngày 24 tháng 1 năm 2026 (giờ UTC) "month" "GMT+06:32:43" 2026-01-01T06:32:43 UTC

UNIX_MICROS_TO_TIMESTAMP

Cú pháp:

unix_micros_to_timestamp(input: INT64) -> TIMESTAMP

Nội dung mô tả:

Chuyển đổi input (được hiểu là số micrô giây kể từ 1970-01-01 00:00:00 UTC) thành TIMESTAMP. Gửi error nếu không thể chuyển đổi input thành TIMESTAMP hợp lệ.

Ví dụ:

input unix_micros_to_timestamp(input)
0L 01-01-1970 00:00:00 (giờ UTC)
400123456L 1970-01-01 00:06:40.123456 UTC
-1000000L 1969-12-31 23:59:59 UTC
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMicros").unixMicrosToTimestamp().as("createdAtString")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixMicrosToTimestamp(field("createdAtMicros")).as("createdAtString"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.UnixMicrosToTimestamp(firestore.FieldOf("createdAtMicros")).As("createdAtString"),
	)).
	Execute(ctx)

UNIX_MILLIS_TO_TIMESTAMP

Cú pháp:

unix_millis_to_timestamp(input: INT64) -> TIMESTAMP

Nội dung mô tả:

Chuyển đổi input (được diễn giải là số mili giây kể từ 1970-01-01 00:00:00 UTC) thành TIMESTAMP. Gửi error nếu không thể chuyển đổi input thành TIMESTAMP hợp lệ.

Ví dụ:

input unix_millis_to_timestamp(input)
0L 01-01-1970 00:00:00 (giờ UTC)
4000123L 1970-01-01 01:06:40.123 UTC
-1000000L 1969-12-31 23:43:20 UTC
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtMillis").unixMillisToTimestamp().as("createdAtString")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixMillisToTimestamp(field("createdAtMillis")).as("createdAtString"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.UnixMillisToTimestamp(firestore.FieldOf("createdAtMillis")).As("createdAtString"),
	)).
	Execute(ctx)

UNIX_SECONDS_TO_TIMESTAMP

Cú pháp:

unix_seconds_to_timestamp(input: INT64) -> TIMESTAMP

Nội dung mô tả:

Chuyển đổi input (được hiểu là số giây kể từ 1970-01-01 00:00:00 UTC) thành TIMESTAMP. Gửi error nếu không thể chuyển đổi input thành TIMESTAMP hợp lệ.

Ví dụ:

input unix_seconds_to_timestamp(input)
0L 01-01-1970 00:00:00 (giờ UTC)
60L 01-01-1970 00:01:00 (giờ UTC)
-300L 1969-12-31 23:55:00 UTC
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAtSeconds").unixSecondsToTimestamp().as("createdAtString")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(unixSecondsToTimestamp(field("createdAtSeconds")).as("createdAtString"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.UnixSecondsToTimestamp(firestore.FieldOf("createdAtSeconds")).As("createdAtString"),
	)).
	Execute(ctx)

TIMESTAMP_ADD

Cú pháp:

timestamp_add(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP

Nội dung mô tả:

Thêm amount của unit từ timestamp. Đối số amount có thể là số âm, trong trường hợp đó, đối số này tương đương với TIMESTAMP_SUB.

Đối số unit phải là một chuỗi và là một trong những giá trị sau:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

Trả về lỗi nếu dấu thời gian thu được không nằm trong phạm vi TIMESTAMP.

Ví dụ:

timestamp unit amount timestamp_add(timestamp, unit, amount)
00:00:00 ngày 20 tháng 2 năm 2025 (giờ UTC) "phút" 2L 2025-02-20 00:02:00 UTC
00:00:00 ngày 20 tháng 2 năm 2025 (giờ UTC) "giờ" -4L 2025-02-19 20:00:00 UTC
00:00:00 ngày 20 tháng 2 năm 2025 (giờ UTC) "ngày" 5L 2025-02-25 00:00:00 UTC
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("createdAt").timestampAdd("day", 3653).as("expiresAt")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampAdd(field("createdAt"), "day", 3653).as("expiresAt"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.TimestampAdd(firestore.FieldOf("createdAt"), "day", 3653).As("expiresAt"),
	)).
	Execute(ctx)

TIMESTAMP_SUB

Cú pháp:

timestamp_sub(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP

Nội dung mô tả:

Trừ amount của unit khỏi timestamp. Đối số amount có thể là số âm, trong trường hợp đó, đối số này tương đương với TIMESTAMP_ADD.

Đối số unit phải là một chuỗi và là một trong những giá trị sau:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

Trả về lỗi nếu dấu thời gian thu được không nằm trong phạm vi TIMESTAMP.

Ví dụ:

timestamp unit amount timestamp_sub(timestamp, unit, amount)
00:00, 04-07-2026 (giờ UTC) "phút" 40L 2026-07-03 23:20:00 UTC
00:00, 04-07-2026 (giờ UTC) "giờ" -24L 00:00, 05-07-2026 (giờ UTC)
00:00, 04-07-2026 (giờ UTC) "ngày" 3L 00:00, 01-07-2026 (giờ UTC)
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("expiresAt").timestampSubtract("day", 14).as("sendWarningTimestamp")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampSubtract(field("expiresAt"), "day", 14).as("sendWarningTimestamp"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.TimestampSubtract(firestore.FieldOf("expiresAt"), "day", 14).As("sendWarningTimestamp"),
	)).
	Execute(ctx)

TIMESTAMP_TO_UNIX_MICROS

Cú pháp:

timestamp_to_unix_micros(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64

Nội dung mô tả:

Chuyển đổi input thành số micrô giây kể từ 1970-01-01 00:00:00 UTC. Cắt bớt các mức độ chính xác cao hơn bằng cách làm tròn xuống đầu micro giây.

Ví dụ:

input timestamp_to_unix_micros(input)
01-01-1970 00:00:00 (giờ UTC) 0L
1970-01-01 00:06:40.123456 UTC 400123456L
1969-12-31 23:59:59 UTC -1000000L
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMicros().as("unixMicros")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixMicros(field("dateString")).as("unixMicros"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.TimestampToUnixMicros(firestore.FieldOf("dateString")).As("unixMicros"),
	)).
	Execute(ctx)

TIMESTAMP_TO_UNIX_MILLIS

Cú pháp:

timestamp_to_unix_millis(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64

Nội dung mô tả:

Chuyển đổi input thành số mili giây kể từ 1970-01-01 00:00:00 UTC. Cắt bớt các mức độ chính xác cao hơn bằng cách làm tròn xuống đầu mili giây.

Ví dụ:

input timestamp_to_unix_millis(input)
01-01-1970 00:00:00 (giờ UTC) 0L
1970-01-01 01:06:40.123 UTC 4000123L
1969-12-31 23:43:20 -1000000L
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixMillis().as("unixMillis")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixMillis(field("dateString")).as("unixMillis"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.TimestampToUnixMillis(firestore.FieldOf("dateString")).As("unixMillis"),
	)).
	Execute(ctx)

TIMESTAMP_TO_UNIX_SECONDS

Cú pháp:

timestamp_to_unix_seconds(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64

Nội dung mô tả:

Chuyển đổi input thành số giây kể từ 1970-01-01 00:00:00 UTC. Cắt bớt các mức độ chính xác cao hơn bằng cách làm tròn xuống đầu giây.

Ví dụ:

input timestamp_to_unix_seconds(input)
01-01-1970 00:00:00 (giờ UTC) 0L
01-01-1970 00:01:00 (giờ UTC) 60L
1969-12-31 23:55:00 UTC -300L
Node.js
const result = await db.pipeline()
  .collection("documents")
  .select(
    field("dateString").timestampToUnixSeconds().as("unixSeconds")
  )
  .execute();

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()
)
Java
Pipeline.Snapshot result =
    firestore
        .pipeline()
        .collection("documents")
        .select(timestampToUnixSeconds(field("dateString")).as("unixSeconds"))
        .execute()
        .get();
Bắt đầu
snapshot := client.Pipeline().
	Collection("documents").
	Select(firestore.Fields(
		firestore.TimestampToUnixSeconds(firestore.FieldOf("dateString")).As("unixSeconds"),
	)).
	Execute(ctx)

TIMESTAMP_DIFF

Cú pháp:

timestamp_diff(end: TIMESTAMP | BSON_TIMESTAMP, start: TIMESTAMP | BSON_TIMESTAMP, unit: STRING) -> INT64

Nội dung mô tả:

Trả về số nguyên của các khoảng unit được chỉ định giữa hai TIMESTAMP.

  • Trả về giá trị âm nếu end đứng trước start.
  • Cắt bớt mọi đơn vị phân số. Ví dụ: timestamp_diff("2021-01-01 00:00:01", "2021-01-01 00:00:00", "minute") trả về 0.

Đối số unit phải là một chuỗi và là một trong những giá trị sau:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day

Ví dụ:

end start unit timestamp_diff(end, start, unit)
00:01, 04-07-2026 (giờ UTC) 00:00, 04-07-2026 (giờ UTC) "second" 60L
00:00, 04-07-2026 (giờ UTC) 00:00, 05-07-2026 (giờ UTC) "ngày" -1L
00:00:59 ngày 4 tháng 7 năm 2026 (giờ UTC) 00:00, 04-07-2026 (giờ UTC) "phút" 0L

TIMESTAMP_EXTRACT

Cú pháp:

timestamp_extract(timestamp: TIMESTAMP | BSON_TIMESTAMP, part: STRING[, timezone: STRING]) -> INT64

Nội dung mô tả:

Trích xuất một part cụ thể (ví dụ: năm, tháng, ngày) từ timestamp.

Đối số part phải là một chuỗi và là một trong những giá trị sau:

  • microsecond
  • millisecond
  • second
  • minute
  • hour
  • day
  • dayofweek: Trả về một giá trị từ 1 (Chủ Nhật) đến 7 (thứ Bảy).
  • dayofyear
  • week: Trả về số tuần trong năm, bắt đầu từ 1 cho Chủ Nhật đầu tiên của năm.
  • week([weekday]): Trả về số tuần trong năm, bắt đầu từ weekday được chỉ định.
  • month
  • quarter
  • year
  • isoweek: Trả về số tuần theo tiêu chuẩn ISO 8601.
  • isoyear: Trả về năm đánh số tuần theo tiêu chuẩn ISO 8601.

Nếu bạn cung cấp đối số timezone, thì việc trích xuất sẽ dựa trên lịch của múi giờ đã cho. Quá trình trích xuất sẽ tuân theo giờ mùa hè.

Nếu bạn không cung cấp timezone, thì quá trình trích xuất sẽ dựa trên UTC.

Đối số timezone phải là chuỗi đại diện cho múi giờ trong cơ sở dữ liệu múi giờ, ví dụ: America/New_York. Bạn cũng có thể sử dụng độ lệch thời gian tuỳ chỉnh bằng cách chỉ định độ lệch so với GMT.

Ví dụ:

timestamp part timezone timestamp_extract(timestamp, part, timezone)
2025-02-20 10:20:30 UTC "year" Không được cung cấp 2025
2025-02-20 10:20:30 UTC "ngày" Không được cung cấp 20
2025-12-31 23:59:59 UTC "year" "Châu Á/Tokyo" 2026