Null values and date formats
I need to format a date string in a report. The following works in a calculated field: (ESTABLISHED.ToString("d")) it returns 1/15/2001
However, in another instance I need a date format but need to check for null values first. The following formula isn't working as expected: (REVISED == Null ? "" : REVISED.ToString("d"))
The formula handles the null values correctly but always includes the time stamp in the date format as follows: 1/15/2001 12:00:00
I have tried reversing the null check (i.e. REVISED != Null) but is always gives the same result.
Any suggestions?
-
Hi Bryan,
How are you obtaining your date? Sometimes when we have a date in a report, it is actually a string, so you may be converting the literal string "1/15/2001 12:00:00" into another string.
You should be able to add another text field or label that uses REVISED.GetType().ToString() as its source, which will display the data type of the REVISED field.
0 -
Value is coming back as a System.DateTime
I get the following formula to work as expected:
REVISED != System.DBNull.Value ? "Not Null" : "Is Null"
The following also works but returns the entire date time string (i.e. 8/1/2011 12:00:00 AM):
REVISED != System.DBNull.Value ? REVISED : "Is Null"
However, as soon as I try to format the date string I get an error for NULL values:
REVISED != System.DBNull.Value ? REVISED.ToString("d") : "Is Null"
Any other suggestions?
0 -
The problem is that all three of the elements of that statement get evaluated regardless of whether the test works out to true or false. So even though you aren't trying to format the string when it is null, and you aren't going to use the output of that statement, the statement is evaluated anyway and throws an error.
There is a workaround for this behavior detailed in this thread:
http://support.geocortex.com/SupportForums/Thread.aspx?pageid=0&mid=2&ItemID=2&thread=46159
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
3 Kommentare