checking if date field is null

Hello,

I'm trying to check if a DateTime field is null and eventually found that the following was returning the year 0001 when the DateTime field was null:

the following doesn't work because it will return '1' for a null DateTime entry:

bool taskExecuted = !string.IsNullOrEmpty(((DateTime)Report.GetColumnValue("Task.ExecuteTime")).ToString())

I eventually used this method which is working but feels wrong:

bool taskExecutedYearX = !((DateTime)Report.GetColumnValue("Task.ExecuteTime")).Year.ToString().Equals("1")

Is there a better way to check a nullable DateTime field in FR?

Thank you.

Comments

  • Hello!

    In the report script, Report.GetColumnValueNullable(...) (returns null or DBNull without converting to 0001-01-01):

    object raw = Report.GetColumnValueNullable(‘Task.ExecuteTime’);
    bool hasDate = raw != null && !(raw is DBNull);
    

    In text or script expressions, use the built-in IsNull(‘Task.ExecuteTime’) function 

    [IIf(IsNull(‘Task.ExecuteTime’), “NULL”, FormatDateTime((DateTime)[Task.ExecuteTime], ‘yyyy-MM-dd’))]

This discussion has been closed.