获取特定时间和格式到文本字段

时间:2018-02-14 15:19:59

标签: text reporting-services time

我需要在字段中获取小时并转换为SSRS表达式中的特定时间。下面是我的代码,但当然我收到了一个错误。

我需要的是如果时间是在00:00到00:59之间,我需要它读取12AM。

任何帮助都将不胜感激。

=IIF((Fields!DischargeTime.Value,”HH”) = 00,"12AM" and
    IIF(Fields!DischargeTime.Value,”HH”)  < 01 “12AM”, 
   IIF(Fields!DischargeTime.Value,”HH”)   >= 01,"1AM" and
      IIF(Fields!DischargeTime.Value,”HH”)  < 02, “1AM”)

1 个答案:

答案 0 :(得分:0)

一个想法,如果你可以调整你的SQL,只需在SQL中处理它(将getdate()调整到你的列:)

 select  
        case when datepart(hour,getdate()) <= 12 then convert(varchar(50), datepart(hour,getdate())) + 'AM'
             else convert(varchar(50), 24-datepart(hour,getdate())) +'PM'
             end as DischargeHour

或者,如果您需要保留SSRS,这似乎有效:

=Choose(DatePart("h",  Fields!DischargeDate.Value)+1,"12AM","1AM","2AM","3AM","4AM","5AM","6AM","7AM","8AM","9AM","10AM","11AM","12PM","1PM","2PM","3PM","4PM","5PM","6PM","7PM","8PM","9PM","10PM","11PM","12PM")