DateTime as empty String or null ?How to check?
Solution 1
=IIf(FormatDateTime(Fields!D_DateTime.Value,2)=CDate("1/1/0001"),"",FormatDateTime(Fields!D_DateTime.Value,2))
Thanks a lot ,i think this fixes my problem.
Solution 2
As I told you in my comment, you should check if your date is DateTime.MinValue
(the minimum value a date can assume, which is exactly 01/01/0001).
if (your_date_property == DateTime.MinValue)
{
// Do what you need
}
Solution 3
Like @Marco suggested you can check for MinValue
. And if you want to pass NULL
to the nullable parameter, you can use the following code for reportviewer
parameter.
Vb.Net
Dim rpFrom As New ReportParameter("FromDate", New String() {Nothing}, False)
C#
ReportParameter rpFrom = new ReportParameter("FromDate", new string[] { null }, false);
Solution 4
As datetime is a struct rather than class i.e. a value type rather than a reference type; it must be initialized with some value. It cannot have null values.
Hence to check the default value you should check the equality with DateTime.MinValue
i.e.
if(D_DateTime.Value == DateTime.MinValue)
{
//write code here for default value handling
}
Solution 5
Change the type of the field in the dataset (rd:TypeName
) to System.Nullable (Of System.DateTime)
. Then you can simply test =Fields!D_DateTime.Value Is Nothing
.
Anyname Donotcare
Updated on May 16, 2020Comments
-
Anyname Donotcare almost 4 years
Q:
I want to check the DateTime against
null value
to empty the cell in my report if the datetime is null.but i don't know how to do this :it appears like this1/1/0001
if it was null.and i want it to be empty cell.This is the datatype in my dataset :
and this is the expression value of my column :
=FormatDateTime(Fields!D_DateTime.Value,2)