I'm reading back a nullable DateTime?
property then assigning that value to a string property in short date format.
I can convert the date time value to a short date string and assign to the IT_Date_String
property. But I'm not sure how to assign a ""
value to the string if the IT_Date
is null.
How can you convert a datetime? value to string.empty when datetime? is null?
This is the assignment in linq:
var status_list = query_all.ToList().Select(r => new RelStatus
{
IT_Date_String = r.IT_Date.Value.ToString("yyyy-MM-dd") != null ? r.IT_Date.Value : null
}).ToList();
And the properties in the model:
public DateTime? IT_Date { get; set; }
public string IT_Date_String { get; set; }