gpt4 book ai didi

azure - 转换 MMM DD YYYY HH :mm:ss datetime format to dd-mm-yyyy HH:mm:ss in Azure DataFlow

转载 作者:行者123 更新时间:2023-12-03 06:13:32 25 4
gpt4 key购买 nike

如何将 Jun 18 2023 8:55:31 PM 等日期时间格式转换为 18-06-2023 20:55:31 dd-mm -yyyy HH:mm:ss 作为 ADF 数据流中的派生列步骤?

最佳答案

据此Documentation ,ADF 数据流表达式不支持上述日期格式。我尝试使用数据流表达式将上述 MMM dd yyyy 格式转换为所需格式,但得到空值。

因此,作为解决方法,您可以尝试使用字符串操作将它们转换为所需的格式。为此,您需要将源日期列作为投影中的字符串列。

首先在数据流中使用以下值创建一个数组参数(MMM 中的月份-MM 中的月份)

["Jan-01","Feb-02","Mar-03","Apr-04","May-05","Jun-06","Jul-07","Aug-08","SeptSep-09","Oct-10","Nov-11","Dec-12"]

enter image description here

在派生列转换中使用以下表达式来生成输出。

concat(split(date,' ')[2], '-',split(find($arr,instr(#item,split(date,' ')[1])!=0),'-')[2],'-',split(date,' ')[3],' ',iif(instr(date,'PM')==0,split(date,' ')[4],replace(split(date,' ')[4],split(split(date,' ')[4],':')[1],toString(add(12,toInteger(split(split(date,' ')[4],':')[1]))))))

示例:日期为 2023 年 6 月 18 日晚上 8:55:31

  • 首先我们需要的是日期,所以如果用空格 ' ' 分割输入列,我将得到第二项,即。 18
  • 对于月份,我通过拆分来获取 MMM 值,并将该值与数组值进行比较,以获取 MM 值。
  • 然后添加年份。对于时间,如果包含'PM',则在小时后添加12并替换原始字符串中的小时。如果不包含'PM',则添加相同的字符串。

结果:

enter image description here

(或)

如果你想在不使用数组的情况下达到你的要求,你可以试试这个:

concat(substring(split(toString(toTimestamp(date, 'MMM dd yyyy hh:mm:ss a')),'-')[3],1,2),dropLeft(replace(toString(toTimestamp(date, 'MMM dd yyyy hh:mm:ss a')),substring(split(toString(toTimestamp(date, 'MMM dd yyyy hh:mm:ss a')),'-')[3],1,2),split(toString(toTimestamp(date, 'MMM dd yyyy hh:mm:ss a')),'-')[1]),4))

enter image description here

关于azure - 转换 MMM DD YYYY HH :mm:ss datetime format to dd-mm-yyyy HH:mm:ss in Azure DataFlow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76501304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com