Generic Inquiry中DateTime字段时间部分格式化问题求助
解决Acumatica Generic Inquiry中DateTime时间部分格式化的问题
我之前在Acumatica的Generic Inquiry里也碰到过一模一样的DateTime时间格式化困扰,给你分享几个亲测有效的解决思路:
用DatePart()替代Hour()实现基础时间拼接
既然GI里不支持直接用Hour()函数,但Minute()可用,我们可以用DatePart("h", [YourDateTimeField])来获取小时部分(这个函数是GI公式引擎支持的)。如果只需要简单的HH:mm格式,可以这么写:=CStr(DatePart("h", [YourDateTimeField])) + ":" + CStr([YourDateTimeField].Minute)如果需要补零(比如把9:5变成09:05),可以结合
IIf()判断来处理:=IIf(DatePart("h", [YourDateTimeField]) <10, "0"+CStr(DatePart("h", [YourDateTimeField])), CStr(DatePart("h", [YourDateTimeField]))) + ":" + IIf([YourDateTimeField].Minute <10, "0"+CStr([YourDateTimeField].Minute), CStr([YourDateTimeField].Minute))通过自定义DAC字段实现更灵活的格式化
如果GI的公式限制太多,且你有权限修改DAC的话,直接在对应的数据访问类里加一个计算字段会更省心。比如:[PXString] [PXUIField(DisplayName = "格式化时间")] public virtual string FormattedTime { get { if (this.YourDateTimeField == null) return string.Empty; // 这里可以根据需求自定义格式,比如HH:mm:ss或者h:mm tt return this.YourDateTimeField.Value.ToString("HH:mm"); } }写完后发布DAC,再在Generic Inquiry里直接选择这个新字段就行,完全不用在GI里写复杂公式。
关于Format()和Hour()函数的说明
你碰到的Format()函数报错,是因为Acumatica GI的公式引擎并没有实现这个方法,所以暂时没法直接调用。而Hour()提示不支持,是因为GI的公式语法里没有内置这个运算符,用DatePart()就是官方推荐的替代方案。
内容的提问来源于stack exchange,提问作者Tony Lanzer
相关产品推荐
相关产品推荐

