如何将SSRS中的时间格式设置为HH:MM AM / PM格式?
问题描述:
我的任务是增加以下代码来显示无秒钟的时间,AM / PM:
I was tasked with augmenting the following code to display the time without seconds, and with AM/PM:
=IIF(Fields!New_Date.Value <> "NO CHANGE", FormatDateTime(IIF(Fields!New_Date.Value = "NO CHANGE","1/1/12",Fields!New_Date.Value),DateFormat.ShortDate), "") &
IIF(Fields!New_Time.Value <> "NO CHANGE",FormatDateTime(IIF(Fields!New_Time.Value = "NO CHANGE","00:00",Fields!New_Time.Value),DateFormat.ShortTime), "")
为了意识到FormatDateTime对于我正在努力做的不够,发现以下内容没有起作用(只是查看与时间段相关的snippit):
In realizing that FormatDateTime was insufficient for what I was trying to do, I found the following did not work (just looking at the snippit that relates to the time fields), :
Format(IIF(Fields!New_Time.Value = "NO CHANGE","00:00",Fields!New_Time.Value),"HH:mm tt")
或者这个
Format(IIF(Fields!New_Time.Value = "NO CHANGE","00:00",Fields!New_Time.Value),"HH:MM tt")
I从这里。
我做错了什么?
答
所以我发现,因为我本质上是tryi为了格式化文本框,SSRS从来没有真正知道这是一个时间字段。虽然我不是100%肯定我的推理是正确的,但它确实解释了为什么以下工作:
So I found that because I was essentially trying to format a textbox, SSRS never really 'knew' that it was a time field. While I'm not 100% sure my reasoning is correct, it does explain why the following works:
Format(CDate(IIF(Fields!New_Time.Value = "NO CHANGE","00:00",Fields!New_Time.Value)),"hh:mm tt")