ฟังก์ชันการประทับเวลา
| ชื่อ | คำอธิบาย |
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
|
TIMESTAMP_DIFF
|
แสดงผลจำนวนเต็มของช่วงเวลา unit ที่ระบุระหว่าง TIMESTAMP 2 ค่า
|
TIMESTAMP_EXTRACT
|
ดึงข้อมูล part ที่เฉพาะเจาะจง (เช่น ปี เดือน วัน) จาก TIMESTAMP
|
CURRENT_TIMESTAMP
ไวยากรณ์:
current_timestamp() -> TIMESTAMP
คำอธิบาย:
รับการประทับเวลาที่จุดเริ่มต้นของเวลาที่ส่งคำขอ input (ตีความว่าเป็นจำนวนไมโครวินาทีนับตั้งแต่ 1970-01-01 00:00:00 UTC)
ค่านี้จะคงที่ภายในคำค้นหา และจะแสดงผลเป็นค่าเดียวกันเสมอหากมีการเรียกใช้หลายครั้ง
TIMESTAMP_TRUNC
ไวยากรณ์:
timestamp_trunc(timestamp: TIMESTAMP | BSON_TIMESTAMP, granularity: STRING[, timezone: STRING]) -> TIMESTAMP
คำอธิบาย:
ตัดการประทับเวลาให้สั้นลงตามรายละเอียดที่ระบุ
อาร์กิวเมนต์ granularity ต้องเป็นสตริงและเป็นค่าใดค่าหนึ่งต่อไปนี้
microsecondmillisecondsecondminutehourdayweekweek([weekday])monthquarteryearisoyear
หากระบุอาร์กิวเมนต์ 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 | "วินาที" | ไม่ได้ระบุข้อมูล | 01-01-2001 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 |
| 16-03-2001 04:00:00 UTC | "week(friday) | ไม่ได้ระบุข้อมูล | 2001-03-16 00:00:00 UTC |
| 23-03-2001 04:00:00 UTC | "week(friday) | "America/Los_Angeles" | 23-03-2001 17:00:00 UTC |
| 24-01-2026 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 แสดง error หากไม่สามารถแปลง input เป็น TIMESTAMP ที่ถูกต้องได้
ตัวอย่างเช่น
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 |
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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixMicrosToTimestamp(firestore.FieldOf("createdAtMicros")).As("createdAtString"), )). Execute(ctx)
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) |
|---|---|
| 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 |
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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixMillisToTimestamp(firestore.FieldOf("createdAtMillis")).As("createdAtString"), )). Execute(ctx)
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) |
|---|---|
| 0L | 1970-01-01 00:00:00 UTC |
| 60 ลิตร | 1970-01-01 00:01:00 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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.UnixSecondsToTimestamp(firestore.FieldOf("createdAtSeconds")).As("createdAtString"), )). Execute(ctx)
TIMESTAMP_ADD
ไวยากรณ์:
timestamp_add(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
คำอธิบาย:
เพิ่ม amount ของ unit จาก timestamp อาร์กิวเมนต์ amount อาจเป็นค่าลบ ซึ่งในกรณีนี้จะเทียบเท่ากับ TIMESTAMP_SUB
อาร์กิวเมนต์ unit ต้องเป็นสตริงและเป็นค่าใดค่าหนึ่งต่อไปนี้
microsecondmillisecondsecondminutehourday
แสดงข้อผิดพลาดหากการประทับเวลาที่ได้ไม่อยู่ในช่วง TIMESTAMP
ตัวอย่างเช่น
timestamp |
unit |
amount |
timestamp_add(timestamp, unit, amount) |
|---|---|---|---|
| 20-02-2025 00:00:00 UTC | "minute" | 2L | 20-02-2025 00:02:00 UTC |
| 20-02-2025 00:00:00 UTC | "hour" | -4L | 19-02-2025 20:00:00 UTC |
| 20-02-2025 00:00:00 UTC | "day" | 5L | 25-02-2025 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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampAdd(firestore.FieldOf("createdAt"), "day", 3653).As("expiresAt"), )). Execute(ctx)
TIMESTAMP_SUB
ไวยากรณ์:
timestamp_sub(timestamp: TIMESTAMP | BSON_TIMESTAMP, unit: STRING, amount: INT64) -> TIMESTAMP
คำอธิบาย:
ลบ amount ของ unit ออกจาก timestamp อาร์กิวเมนต์ amount อาจเป็นค่าลบได้ ซึ่งในกรณีนี้จะเทียบเท่ากับ TIMESTAMP_ADD
อาร์กิวเมนต์ unit ต้องเป็นสตริงและเป็นค่าใดค่าหนึ่งต่อไปนี้
microsecondmillisecondsecondminutehourday
แสดงข้อผิดพลาดหากการประทับเวลาที่ได้ไม่อยู่ในช่วง 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 |
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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampSubtract(firestore.FieldOf("expiresAt"), "day", 14).As("sendWarningTimestamp"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_MICROS
ไวยากรณ์:
timestamp_to_unix_micros(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
คำอธิบาย:
แปลง input เป็นจำนวนไมโครวินาทีตั้งแต่ 1970-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 |
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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixMicros(firestore.FieldOf("dateString")).As("unixMicros"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_MILLIS
ไวยากรณ์:
timestamp_to_unix_millis(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
คำอธิบาย:
แปลง input เป็นจำนวนมิลลิวินาทีนับตั้งแต่ 1970-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 |
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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixMillis(firestore.FieldOf("dateString")).As("unixMillis"), )). Execute(ctx)
TIMESTAMP_TO_UNIX_SECONDS
ไวยากรณ์:
timestamp_to_unix_seconds(input: TIMESTAMP | BSON_TIMESTAMP) -> INT64
คำอธิบาย:
แปลง input เป็นจำนวนวินาทีนับตั้งแต่ 1970-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 | 60 ลิตร |
| 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();
Go
snapshot := client.Pipeline(). Collection("documents"). Select(firestore.Fields( firestore.TimestampToUnixSeconds(firestore.FieldOf("dateString")).As("unixSeconds"), )). Execute(ctx)
TIMESTAMP_DIFF
ไวยากรณ์:
timestamp_diff(end: TIMESTAMP | BSON_TIMESTAMP, start: TIMESTAMP | BSON_TIMESTAMP, unit: STRING) -> INT64
คำอธิบาย:
แสดงผลจำนวนเต็มของช่วงเวลา unit ที่ระบุระหว่าง TIMESTAMP 2 ค่า
- แสดงผลเป็นค่าลบหาก
endอยู่ก่อนstart - ตัดหน่วยเศษส่วนออก เช่น
timestamp_diff("2021-01-01 00:00:01", "2021-01-01 00:00:00", "minute")จะแสดงผลเป็น0
อาร์กิวเมนต์ unit ต้องเป็นสตริงและเป็นค่าใดค่าหนึ่งต่อไปนี้
microsecondmillisecondsecondminutehourday
ตัวอย่างเช่น
end |
start |
unit |
timestamp_diff(end, start, unit) |
|---|---|---|---|
| 2026-07-04 00:01:00 UTC | 2026-07-04 00:00:00 UTC | "วินาที" | 60 ลิตร |
| 2026-07-04 00:00:00 UTC | 2026-07-05 00:00:00 UTC | "day" | -1L |
| 2026-07-04 00:00:59 UTC | 2026-07-04 00:00:00 UTC | "minute" | 0L |
TIMESTAMP_EXTRACT
ไวยากรณ์:
timestamp_extract(timestamp: TIMESTAMP | BSON_TIMESTAMP, part: STRING[, timezone: STRING]) -> INT64
คำอธิบาย:
ดึงข้อมูล part ที่เฉพาะเจาะจง (เช่น ปี เดือน วัน) จาก timestamp
อาร์กิวเมนต์ part ต้องเป็นสตริงและเป็นค่าใดค่าหนึ่งต่อไปนี้
microsecondmillisecondsecondminutehourdaydayofweek: แสดงผลค่าระหว่าง 1 (วันอาทิตย์) ถึง 7 (วันเสาร์)dayofyearweek: แสดงผลหมายเลขสัปดาห์ของปี โดยเริ่มที่ 1 สำหรับวันอาทิตย์แรกของปีweek([weekday]): แสดงผลหมายเลขสัปดาห์ของปี โดยเริ่มจากweekdayที่ระบุmonthquarteryearisoweek: แสดงผลหมายเลขสัปดาห์ตามมาตรฐาน ISO 8601isoyear: แสดงปีที่ระบุหมายเลขสัปดาห์ตามมาตรฐาน ISO 8601
หากระบุอาร์กิวเมนต์ timezone การดึงข้อมูลจะอิงตามปฏิทินของเขตเวลาที่ระบุ การดึงข้อมูลจะอิงตามเวลาออมแสง
หากไม่ได้ระบุ timezone ระบบจะดึงข้อมูลตาม UTC
อาร์กิวเมนต์ timezone ควรเป็นการแสดงสตริงของเขตเวลาจากฐานข้อมูลเขตเวลา เช่น America/New_York นอกจากนี้ คุณยังใช้ออฟเซ็ตเวลาที่กำหนดเองได้โดยระบุออฟเซ็ตจาก GMT
ตัวอย่างเช่น
timestamp |
part |
timezone |
timestamp_extract(timestamp, part, timezone) |
|---|---|---|---|
| 20-02-2025 10:20:30 UTC | "year" | ไม่ได้ระบุข้อมูล | 2025 |
| 20-02-2025 10:20:30 UTC | "day" | ไม่ได้ระบุข้อมูล | 20 |
| 31-12-2025 23:59:59 UTC | "year" | "Asia/Tokyo" | 2026 |