0

I want to format year to this format yy = 17 i tried with this code but not working it is wrong format .

<select id="CreditCardExpiryDateYear" class="dropdown form-control">
       @for (var iYear = DateTime.Now.Year; iYear <= DateTime.Now.Year + 10; iYear++)
          {
           <option value="@iYear.ToString("yy")" @(DateTime.Now.Year == iYear ? " selected" : "")>@iYear.ToString("yy")</option>
          }
</select>
hashim
  • 91
  • 2
  • 14

2 Answers2

3

The format applies to the type DateTime, not the Year property which is int. Either use DateTime.Now.ToString("yy"), or iYear % 100

adiga
  • 34,372
  • 9
  • 61
  • 83
Treziac
  • 3,056
  • 1
  • 17
  • 19
0

Why not do like this -

(iYear% 100)
Ipsit Gaur
  • 2,872
  • 1
  • 23
  • 38