I have a program which calls a service when it is executed, it gives me certain values as a result and these are saved in a csv file. One of those values is a date which, when empty, shows me 1/1/0001 12:00:00 AM as the minimum value.
What I would like is that before the result is shown, to be able to replace this date with a null or empty value so as not to have to show that date with values that can confuse the user.
This is part of my code:
newLine = string.Format("\"{0}\",\"{1}\"",
item.InvitationDate, //Convert.ToDateTime(String.IsNullOrEmpty(item.InvitationDate) ? "" :
item.Reminder1SentDate);
As you can see, the field item.invitationDate
is the one that gives me as a result what I indicated above. After the comment is what I have tried to do but I have not been successful
Thank you
The property
InvitationDate
has to be nullable in order to achieve what you want. In your case, when you don't initialize a propertyInvitationDate
value, the default value that is assigned is 1/1/0001 12:00:00 AM.Make the property nullable so you can tell if it's null, then display an empty space.
In the class where the property is defined, you define it as nullable like so:
So when doing the format it would be like this:
Since you have a
1/1/0001 12:00:00 AM
, that means you have the minimum value assigned to your variable of typeDateTime
.To fix it, you simply have to compare against that value, for example: