I have the following where I need to get only the Date (not datetime) from ReqDate and RepDeclined which are both nullable datetime fields.
var info = from pr in db.Prog
join tf in db.In_Lens
on pr.PID equals tf.PID
select new
{ ReqDate = String.Format("{0:MM/dd/yyyy}",tf.ReqDate),
ReqDeclinedDate = tf.ReqDeclined.ToString("MM/dd/yyyy")
}).ToList()
It is not working as ReqDate and RepDeclined are both nullable datetime fields. I also tried String.Format but no luck.
Do
to avoid the NullReferenceException caused by the
.ToStringcall on a null object.or
Use
String.Formatin both cases: