title: C# Datetime - Add days or month
body: <p>I'm trying to add days or month to a datetime. What determines rather it should add days or month to the datetime is what dayOrMonth ends with. So for example if dayOrMonth ends with MM it should add month, if it ends with DD it should add days.</p>
  
  <p>dayOrMonth could look like this "90DD" (should add 90 days) and "90MM" should add 90 month.</p>
  
  <p>I'm thinking about creating an extension method of some kind, but I'm struggling abit with the approach to this, as adding more if statements is not an option. </p>
  
  <pre><code>                    //... Set payment dates.
                      string dayOrMonth;
                      for (int x = 0; x &lt; installmentDates.Count; x++)
                      {
                          if (installmentDates.Count &gt; 0)
                          {
                              installmentdDateRow[colName] = installmentdDateRow[colName] + Convert.ToDateTime(installmentDates[x]).ToString("dd'-'MM'-'yyyy") + "\n";
  
                              //... Future payment dates.
                              int futurePaymentColumn = installmentdFuturePayments.Table.Columns.IndexOf(colName);
                              if (colName == "1. rate" &amp;&amp; installmentDates.Count - 1 == x)
                              {
                                  installmentdFuturePayments[futurePaymentColumn + 1] = installmentdFuturePayments[futurePaymentColumn + 1] + Convert.ToDateTime(installmentDates[x]).AddMonths(3).ToString("dd'-'MM'-'yyyy") + "\n";
                              }
                              if (colName == "2. rate" &amp;&amp; installmentDates.Count - 1 == x &amp;&amp; Functions.GetProductInfo(unit.Key.ToString().Split('-')[0])[9] != "€ 0,00")
                              {
                                  installmentdFuturePayments[futurePaymentColumn + 1] = installmentdFuturePayments[futurePaymentColumn + 1] + Convert.ToDateTime(installmentDates[x]).AddMonths(3).ToString("dd'-'MM'-'yyyy") + "\n";
                              }
                          }
                      }
  </code></pre>