跳至主要内容

Date.FromText

根據本地、國際和自訂日期格式建立日期。

Syntax

Date.FromText(
text as text,
optional options as any
) as date

Remarks

從文字表示法建立日期值。

  • text: 要轉換為日期的文字值。
  • options: 選用的 record,可提供用來指定其他屬性。record 可以包含下列欄位:

若要支援舊版工作流程,options 也可以是文字值。這與 options = [Format = null, Culture = options] 具有相同的行爲。

Examples

Example #1

"2010-12-31" 轉換成 date 值。

Date.FromText("2010-12-31")

Result:

#date(2010, 12, 31)

Example #2

使用自訂格式和德文文化特性進行轉換。

Date.FromText("30 Dez 2010", [Format="dd MMM yyyy", Culture="de-DE"])

Result:

#date(2010, 12, 30)

Example #3

在西曆中尋找對應於回曆 1400 年初的日期。

Date.FromText("1400", [Format="yyyy", Culture="ar-SA"])

Result:

#date(1979, 11, 20)

Example #4

將已張貼日期資料行中具有縮寫月份的義大利文文字日期轉換為日期值。

let
Source = #table(type table [Account Code = text, Posted Date = text, Sales = number],
{
{"US-2004", "20 gen. 2023", 580},
{"CA-8843", "18 lug. 2024", 280},
{"PA-1274", "12 gen. 2023", 90},
{"PA-4323", "14 apr. 2023", 187},
{"US-1200", "14 dic. 2023", 350},
{"PTY-507", "4 giu. 2024", 110}
}),
#"Converted Date" = Table.TransformColumns(
Source,
{"Posted Date", each Date.FromText(_, [Culture = "it-IT"]), type date}
)
in
#"Converted Date"

Result:

#table(type table [Account Code = text, Posted Date = date, Sales = number],
{
{"US-2004", #date(2023, 1, 20), 580},
{"CA-8843", #date(2024, 7, 18), 280},
{"PA-1274", #date(2023, 1, 12), 90},
{"PA-4323", #date(2023, 4, 14), 187},
{"US-1200", #date(2023, 12, 14), 350},
{"PTY-507", #date(2024, 6, 4), 110}
})

Category

Date