JamesW

Null DateTime Evaluations

Discussion created by JamesW on Nov 1, 2018
Latest reply on Nov 1, 2018 by ChristofN

I am trying to retrieve the month (in int form) from a DateTime column.

The code is simple for the int column Calculated Value Expression:

 

{

if ([[Birthday]] != null)

{

return [[Birthday]].Month;

}

else

{

return null;

}

}

 

However, we receive an error message when the DateTime field is blank. It reads:

 

Error on evaluating Statements: Line 39 (italic) Cannot implicitly convert type 'object' to 'System.DateTime'. an explicit conversion exists (are you missing a cast?)

 

It would seem that it passes into the first block, wrongly.

 

I have used this formula instead which works, but it would be good to know why it not work when using the DateTime methods?

 

{

if ([[Birthday]] != null)

{

string date = [[Birthday]].ToString().Substring(3,2);

return Int32.Parse(date);

}

else

{

return null;

}

}

Outcomes