Tuesday, July 15, 2014

.Net ReportViewer datetime format problem am/pm

I was having troubles formating a datetime parameter with am/pm. No matter the formatting, it was always missing the am/pm .

 - The expression was Parameters!initDate.Value and I got 2014/01/07 12:00:00
I also tried
 -Format(Parameters!initDate.Value,"yyyy/MM/dd hh:mm:ss tt") and I got 2014/01/07 12:00:00

and so on....

So I decided to use an if to evaluate the hour and manually set the am/pm:

=Format(Parameters!initDate.Value,"yyyy/MM/dd hh:mm:ss ") + IIf(Parameters!initDate.Value.Hour > 11, "pm", "am")