Custom format a date

I’m populating the employeeType field with a calculated value based on the Employee’s status in UKG. For employees that are terminated, I’m trying to populate the termination date as well in the string. It is working with the following

WHEN
Employment.EmployeeStatusCode == ‘T’
THEN
'Terminated as of ’ + Employment.DateOfTermination

The simple expression appears as

(Employment.EmployeeStatusCode == ‘T’)? 'Terminated as of ’ + Employment.DateOfTermination:(Default)? Ignore:null

My question is how would you get just the date from the termination date rather than the whole DateTime value.

I had tried to use…

.Value.ToShortDateString() but I’m sure I’m misunderstanding the syntax since I’m not very familiar with C#.

In cased like this where trying to manipulate the output of a variable in the string, does that need to happen in the “When” part of the expression?

You can specify the format using ToString or even ToShortDateString.

The trick here is that the field Employment.DateOfTermination may be null, so you first have to check for nulls

WHEN
Employment.DateOfTermination != null
THEN
'Terminated as of ’ + Employment.DateOfTermination.GetValueOrDefault().ToString(“MM/dd/yyyy”)
or
'Terminated as of ’ + Employment.DateOfTermination.GetValueOrDefault().ToShortDateString()

WHEN
Default
THEN
Ignore

The simple expression would look like this…

(Employment.DateOfTermination != null)? 'Terminated as of ’ + Employment.DateOfTermination.GetValueOrDefault().ToString(“MM/dd/yyyy”):(Default)? Ignore:null