Expression edit
i am working on a report in asp.net, mvc/c# and in my report i want to display the date without the time so instead of
12/3/2011 00:00:00 ------ to ------ 12/3/2011
and i am using this expression for my text box that is displaying the date:
=FormatDateTime(Fields!DateClosed.Value)
and for an item with a date it does show properly without the time - but for other items in the list which do not have dat开发者_如何学运维e they display the time like so: 12:00:00 AM
How can i fix the expression so that it will only show the date only when there is a date to display and not show the time when a date is not available.
How about:
=(DateClosed==null) ? FormatDateTime(DateClosed) : string.Empty;
Also, you might use
=(DateClosed==null) ? DateClosed.Value.ToString("mm dd yyyy") : string.Empty;
instead of calling a separate FormatDateTime()
function (unless, of course, you need to centralize date formatting, but that could be handled by storing the format in web.config).
Or even
string FormatDateTime(DateTime? date)
{
var result = date==null ? date.ToString("mm dd yyyy") : string.Empty;
}
if you don't want to put the ternary conditional in the markup.
so i played around with this and i used a different format expression which lucky enough worked well. Thanks for everyone how helped.
=Format(Fields!DateClosed.Value, "d")
Check if the date is null and if it is then set string.Empty
精彩评论