---
title: DateTime.Date – ดึงส่วนวันที่จาก DateTime
url: https://www.thepexcel.com/functions/power-query/datetime-functions/datetime-date/
type: function-explainer
program: Power Query
syntax: DateTime.Date(dateTime as any) as nullable date
date: 2025-12-03
updated: 2025-12-23
scores:
  popularity: 7
  difficulty: 2
  usefulness: 7
---

# DateTime.Date – ดึงส่วนวันที่จาก DateTime

> ดึงเฉพาะส่วนวันที่ (Date) ออกจากค่า DateTime หรือ DateTimeZone โดยทิ้งเวลาไป

## คำอธิบาย

ดึงเฉพาะส่วนวันที่ (Date) ออกจากค่า DateTime หรือ DateTimeZone โดยทิ้งเวลาไป

## Syntax

```excel
DateTime.Date(dateTime as any) as nullable date
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| dateTime | Yes | DateTime/DateTimeZone/Date |  | ค่า DateTime, DateTimeZone หรือ Date ที่ต้องการดึงส่วนวันที่ออกมา |

## ตัวอย่าง

### 1. ดึงวันที่จาก DateTime พื้นฐาน

```excel
let
    SampleDateTime = #datetime(2025, 5, 20, 14, 30, 45),
    ExtractedDate = DateTime.Date(SampleDateTime)
in
    ExtractedDate
```

**ผลลัพธ์:** `#date(2025, 5, 20)`

ฟังก์ชัน DateTime.Date ดึงส่วนวันที่ (2025-05-20) ออกจาก DateTime ที่มีเวลา (14:30:45) ผลลัพธ์คือ date ที่ไม่มีเวลา

### 2. ดึงวันที่จาก DateTimeZone

```excel
let
    TimezoneValue = #datetimezone(2025, 12, 31, 23, 59, 59, 8, 0),
    DateOnly = DateTime.Date(TimezoneValue)
in
    DateOnly
```

**ผลลัพธ์:** `#date(2025, 12, 31)`

ทำงานได้ดีกับ DateTimeZone เช่นกัน เมื่อมีค่าเขตเวลาปนมา DateTime.Date จะเอาแค่วันที่ส่วน ทิ้งเวลาและเขตเวลาไป

### 3. แปลงคอลัมน์ DateTime เป็น Date ในตาราง

```excel
let
    SalesData = Table.FromRows(
        {{#datetime(2025, 1, 15, 9, 30, 0), 500}, {#datetime(2025, 1, 15, 14, 45, 0), 750}, {#datetime(2025, 1, 16, 10, 20, 0), 600}},
        {"OrderDateTime", "Amount"}
    ),
    ConvertToDate = Table.TransformColumns(SalesData, {"OrderDateTime", each DateTime.Date(_)})
in
    ConvertToDate
```

**ผลลัพธ์:** `ตารางที่มี OrderDateTime เป็น Date แทน DateTime โดยยังคงค่า Amount ไว้เหมือนเดิม`

ใช้ Table.TransformColumns คู่กับ DateTime.Date เพื่อแปลงคอลัมน์ DateTime เป็น Date ทั้งตาราง วิธีนี้สะดวกกว่าการแยกหรือแต่งตั้งคอลัมน์ใหม่ หรือจะใช้ each DateTime.Date([OrderDateTime]) ก็ได้เช่นกัน

### 4. จัดกลุ่มข้อมูลตามวันที่เมื่อมี DateTime

```excel
let
    TransactionLog = Table.FromRows(
        {{#datetime(2025, 3, 1, 8, 15, 0), "Sale", 1200}, {#datetime(2025, 3, 1, 15, 45, 0), "Return", 300}, {#datetime(2025, 3, 2, 10, 0, 0), "Sale", 1500}},
        {"Timestamp", "Type", "Amount"}
    ),
    AddDateColumn = Table.AddColumn(TransactionLog, "Date", each DateTime.Date([Timestamp])),
    GroupByDate = Table.Group(AddDateColumn, {"Date"}, {{"TotalAmount", each List.Sum([Amount]), "Count", each Table.RowCount(_)}})
in
    GroupByDate
```

**ผลลัพธ์:** `ตารางแสดง Date, TotalAmount และ Count โดยจัดกลุ่มตามวันที่`

สถานการณ์จริงที่พบบ่อย: เรามี transaction log ที่มี timestamp ที่มีวินาที แต่ต้องการสรุปตามวันที่ DateTime.Date ช่วยดึงวันที่ออกมา จากนั้น group by ตามวันนั้นได้ถูกต้อง

## หมายเหตุเพิ่มเติม

- ใช้ DateTime.Date เมื่อต้องการเปรียบเทียบหรือจัดกลุ่ม DateTime โดยไม่สนใจเวลา เช่น หา transactions ของวันเดียวกัน

- คู่กับ Table.TransformColumns เพื่อแปลงหลายคอลัมน์พร้อมกัน มีประสิทธิภาพมากกว่าการสร้างคอลัมน์ใหม่แล้วลบของเก่า

- หากต้องดึงส่วนอื่นของ DateTime ให้ใช้ DateTime.Time สำหรับเวลา หรือ DateTime.ToText เพื่อจัดรูปแบบ

- ระวังเวลาเขตเวลา (timezone) ถ้าใช้ DateTimeZone ให้พิจารณาว่าต้องแปลงเป็นเขตเวลาของผู้ใช้หรือไม่ DateTime.Date จะใช้วันที่ตามค่าที่ส่งมา

## คำถามที่พบบ่อย

**Q: DateTime.Date กับ Date.From ต่างกันอย่างไร?**

DateTime.Date ใช้สำหรับดึงส่วน Date จาก DateTime/DateTimeZone ส่วน Date.From เป็นฟังก์ชันแปลงประเภท (type conversion) ที่พยายามแปลง text หรือค่าอื่นๆ เป็น Date DateTime.Date ใช้ดีเมื่อข้อมูลเป็น DateTime อยู่แล้ว

**Q: ถ้าค่าที่ส่งมาเป็น null จะเกิดอะไร?**

DateTime.Date จะส่งคืน null นี่คือพฤติกรรมของฟังก์ชัน nullable ใน Power Query ถ้าต้องการจัดการ null ให้ใช้ Table.ReplaceValue หรือ if statement ในคำสั่ง each

**Q: ใช้ DateTime.Date ได้กับค่า Date ที่เป็นอยู่แล้วหรือไม่?**

ได้ ถ้าส่ง Date เข้าไป DateTime.Date จะคืน Date นั้นกลับมาเหมือนเดิม ไม่มีปัญหา

**Q: เวลาของ DateTime จะหายไปหรือเปลี่ยนหรือไม่?**

ไม่หายไป มันถูกแสดงออกมาเป็นส่วนหนึ่งของค่า DateTime เท่านั้น DateTime.Date แสดงแค่ส่วน Date ส่วนเวลายังอยู่ในค่า DateTime ดั้งเดิม ถ้าต้องดึงเวลาออกมาให้ใช้ DateTime.Time แทน

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn - DateTime.Date](https://learn.microsoft.com/en-us/powerquery-m/datetime-date) _(official)_
- [PowerQuery.how - DateTime Functions](https://powerquery.how/datetime-functions/) _(article)_

---

_Source: [https://www.thepexcel.com/functions/power-query/datetime-functions/datetime-date/](https://www.thepexcel.com/functions/power-query/datetime-functions/datetime-date/)_
