ตัวอย่างที่ 1: รูปแบบมาตรฐาน (ตามเครื่อง)
=Date.ToText(#date(2025, 12, 31))
"31/12/2025" (ขึ้นกับ Region)
แปลงวันที่ให้เป็นข้อความพร้อมจัดรูปแบบ
Date.ToText จะแปลงค่า Date ให้อยู่ในรูป Text String โดยสามารถระบุ options เพื่อกำหนด Format และ Culture ได้ ทำให้สามารถแสดงผลวันที่ในรูปแบบที่ต้องการ
=Date.ToText(date as nullable date, optional options as any, optional culture as nullable text) as nullable text
=Date.ToText(date as nullable date, optional options as any, optional culture as nullable text) as nullable text
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| date | date | Yes | ค่าวันที่ที่ต้องการแปลง | |
| options | any | Optional | null | รูปแบบ (Format String) เช่น “dd/MM/yyyy” หรือ Record [Format=”…”, Culture=”…”] |
| culture | text | Optional | null | รหัสวัฒนธรรม (Culture Code) เช่น “th-TH” (deprecated, use options record instead) |
แปลงวันที่ 2025-01-01 ให้เป็น "01 ม.ค. 2568" สำหรับทำรายงาน
แปลงวันที่เป็น "yyyyMMdd" (เช่น "20250101") เพื่อใช้เป็น Key ในการ Merge
=Date.ToText(#date(2025, 12, 31))
"31/12/2025" (ขึ้นกับ Region)
=Date.ToText(#date(2025, 1, 5), "dd-MMM-yyyy")
"05-Jan-2025"
=Date.ToText(#date(2025, 1, 1), [Format="d MMMM yyyy", Culture="th-TH"])
"1 มกราคม 2568"
ต่างกันครับ yyyy คือปี ค.ศ./พ.ศ. ปกติ แต่ YYYY อาจหมายถึง ISO Week Year ซึ่งอาจให้ผลต่างกันในช่วงข้ามปี ควรใช้ yyyy
ขึ้นอยู่กับเวอร์ชันของ Power Query และ OS แต่โดยปกติ th-TH ควรให้ปี พ.ศ. ถ้าไม่ได้ ให้ลองใช้ “gg” ใน format string ด้วย
ฟังก์ชัน Date.ToText ใน Power Query ใช้สำหรับแปลงค่าวันที่ (Date) ให้เป็นข้อความ (Text) โดยสามารถกำหนดรูปแบบ (Format) ได้ตามต้องการ เช่น “dd/MM/yyyy” หรือ “dd MMM yyyy”