As my title above I got a table in my database that is DateTime datatype and it is null value. And I got this line of code that I am using but I don't know why that it is returning 12:00
string FitaCorIn1 = Convert.ToDateTime(req.FACorrectionIn1).ToString("hh:mm") == null ? "00:00" : Convert.ToDateTime(req.FAIn1).ToString("hh:mm");
string FitaCorOut1 = Convert.ToDateTime(req.FACorrectionOut1).ToString("hh:mm") == null ? "00:00" : Convert.ToDateTime(req.FAIn1).ToString("hh:mm");
So as you can see in my code If the value of datetime is null I want to display 00:00 and if it is not null it will display the current value.
NOTE
12 Hours Format
req.FACorrectionIn1is that the value from the database?ToStringmethod is returning "12:00". Comparing that to null is not evaluating to TRUE. Maybe you don't want to compare the return fromToStringto null. And maybe you don't even need to call theToDateTimemethod. Maybe you are wanting to just check if theFACorrectionIn1member is null.req.FACorrectionIn1? are they string or date timeDateTimecannot be null unless changed to nullable type.ConvertTo.DateTimewill returnDateTime.MinValueif thevalueinput isnull.