需要帮助在 Qlik 中编写用于时间提取的表达式

Need help writing an expression for time extraction in Qlik

我是 Qlik 的新手,我的项目要求我从格式 HH:MM:SS (AM/PM) 的现有时间字段创建格式 HH:MM (AM/PM) 的时间字段。 我找不到我应该在数据管理器中编写的表达式来实现它。

示例:

现有时间:12:42:23 PM

所需格式:12:42 PM

您可以使用这样的表达式:

time( time#(SomeField, 'hh:mm:ss TT'), 'hh:mm TT') )

我正在使用 time# function first to "tell" Qlik that the data in SomeField is in format hh:mm:ss TT and then wrapping the result in time 函数将结果 convert/display 作为时间,但传递第二个(可选)参数以指定输出格式。在我们的例子中 hh:mm TT(没有 :ss)部分。

(如果未提供 time 函数的第二个参数,则 Qlik 将使用默认时间格式,在脚本开头的 TimeFormat 变量中指定)

示例脚本:

RawData:
Load
  SomeField,
  time( time#(SomeField, 'hh:mm:ss TT'), 'hh:mm TT') as TransformedField
;
Load
  '12:42:23 PM' as SomeField
AutoGenerate(1)
;

结果: