Thep Excel

Date.ToText – แปลงวันที่เป็นข้อความ

แปลงวันที่ให้เป็นข้อความพร้อมจัดรูปแบบ

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

By ThepExcel AI Agent
3 December 2025

Syntax & Arguments

=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)

How it works

จัดรูปแบบวันที่เพื่อแสดงผล

แปลงวันที่ 2025-01-01 ให้เป็น "01 ม.ค. 2568" สำหรับทำรายงาน

สร้าง Key สำหรับเชื่อมข้อมูล

แปลงวันที่เป็น "yyyyMMdd" (เช่น "20250101") เพื่อใช้เป็น Key ในการ Merge

Examples

ตัวอย่างที่ 1: รูปแบบมาตรฐาน (ตามเครื่อง)

แปลงเป็นข้อความโดยใช้ Format เริ่มต้นของระบบ
Power Query Formula:

=Date.ToText(#date(2025, 12, 31))

Result:

"31/12/2025" (ขึ้นกับ Region)

ตัวอย่างที่ 2: กำหนด Format เอง

กำหนดรูปแบบเป็น วัน-เดือน(ย่อ)-ปี
Power Query Formula:

=Date.ToText(#date(2025, 1, 5), "dd-MMM-yyyy")

Result:

"05-Jan-2025"

ตัวอย่างที่ 3: ใช้ Culture ไทย (ปี พ.ศ.)

ใช้ Culture="th-TH" จะได้ชื่อเดือนภาษาไทยและปี พ.ศ.
Power Query Formula:

=Date.ToText(#date(2025, 1, 1), [Format="d MMMM yyyy", Culture="th-TH"])

Result:

"1 มกราคม 2568"

FAQs

รูปแบบ yyyy กับ YYYY ต่างกันไหม?

ต่างกันครับ yyyy คือปี ค.ศ./พ.ศ. ปกติ แต่ YYYY อาจหมายถึง ISO Week Year ซึ่งอาจให้ผลต่างกันในช่วงข้ามปี ควรใช้ yyyy

ทำไมใช้ "th-TH" แล้วปีเป็น ค.ศ.?

ขึ้นอยู่กับเวอร์ชันของ Power Query และ OS แต่โดยปกติ th-TH ควรให้ปี พ.ศ. ถ้าไม่ได้ ให้ลองใช้ “gg” ใน format string ด้วย

Resources & Related

Additional Notes

ฟังก์ชัน Date.ToText ใน Power Query ใช้สำหรับแปลงค่าวันที่ (Date) ให้เป็นข้อความ (Text) โดยสามารถกำหนดรูปแบบ (Format) ได้ตามต้องการ เช่น “dd/MM/yyyy” หรือ “dd MMM yyyy”

Leave a Reply

Your email address will not be published. Required fields are marked *