Q:

Linq get Date from DateTime nullable field

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.
It says no overload for method.

A:

You can try this, more elegant i think
  var info = from pr in db.Prog
       join tf in db.In_Lens
       on pr.PID equals tf.PID
       select new
       { ReqDate = !string.IsNullOrEmpty(tf.ReqDate) ? string.Format("{0:MM/dd/yyyy}",tf.ReqDate) : string.Empty(),
         ReqDeclinedDate = !string.IsNullOrEmpty(tf.ReqDeclined) ? tf.ReqDeclined.ToString("MM/dd/yyyy") : string.Empty()
       }).ToList()

