title: How to check if a dateTime Is Null in dataRow?
body: <p>I am writing an web application. I want to check if the dateFrom is null or if dateTo is null. If dateFrom is null, print out dateTo, if dateTo is null, then print out dateFrom. If both of then exist, then print out the formation such as <code>12/3/2015 - 12/3/2015</code>. I have most of the code working, but I cannot figureout how to handle the null date. It keep giving me this exception</p>
  
  <blockquote>
    <p>String was not recognized as a valid DateTime</p>
  </blockquote>
  
  <p>Here is my code</p>
  
  <pre><code>public DataSet SearchTimingReq()
  {
      DateTime effectDateFrom, effectDateTo;
      DataSet ds = someDataSet();    
  
      if (ds != null &amp;&amp; ds.Tables.Count &gt; 0 &amp;&amp; ds.Tables[0].Rows.Count &gt; 0)
      {
          foreach (DataRow row in ds.Tables[0].Rows)
          {
  
              if (Convert.ToDateTime(row["Effect_Date_To"].ToString()).ToString("dd/MM/yyyy") == DateTime.MinValue.ToString())
              {
                    row["Effective_Period"] = effectDateFrom.ToString("dd/MM/yyyy");
              }
  
              if (Convert.ToDateTime(row["Effect_Date_From"].ToString()).ToString("dd/MM/yyyy") == DateTime.MinValue.ToString())
              {
                    row["Effective_Period"] = effectDateTo.ToString("dd/MM/yyyy");
              }
  
              if (effectDateTo != DateTime.MinValue &amp;&amp; effectDateFrom == DateTime.MinValue)
              {
                    row["Effective_Period"] = Convert.ToDateTime(row["Effect_Date_From"].ToString()).ToString("dd/MM/yyyy") + " - " + Convert.ToDateTime(row["Effect_Date_To"].ToString()).ToString("dd/MM/yyyy");
              }    
          }
      }
  }
  </code></pre>
  
  <p>Updated code</p>
  
  <pre><code>if (!DBNull.Value.Equals(row["Effect_Date_From"]))
  {
      row["Effective_Period"] = Convert.ToDateTime(row["Effect_Date_To"].ToString()).ToString("dd/MM/yyyy");
  }
  if (!DBNull.Value.Equals(row["Effect_Date_To"]))
  {
      row["Effective_Period"] = Convert.ToDateTime(row["Effect_Date_From"]).ToString("dd/MM/yyyy");
  }
  
  if (DBNull.Value.Equals(row["Effect_Date_To"]) &amp;&amp; DBNull.Value.Equals(row["Effect_Date_From"]))
  {
      row["Effective_Period"] = Convert.ToDateTime(row["Effect_Date_From"].ToString()).ToString("dd/MM/yyyy") + " - " + Convert.ToDateTime(row["Effect_Date_To"].ToString()).ToString("dd/MM/yyyy");
  }
  </code></pre>