Converting a year from 4 digit to 2 digit and back again in C#

Posted by Mike Wills on Stack Overflow See other posts from Stack Overflow or by Mike Wills
Published on 2008-09-22T15:12:16Z Indexed on 2010/03/24 9:23 UTC
Read the original article Hit count: 334

Filed under:
|
|

My credit card processor requires I send a two-digit year from the credit card expiration date. Here is how I a currently processing:

  1. I put a DropDownList of the 4-digit year on the page.
  2. I validate the expiration date in a DateTime field to be sure that the expiration date being passed to the CC processor isn't expired.
  3. I send a two-digit year to the CC processor (as required). I do this via a substring of the value from the year DDL.

Is there a method out there to convert a four-digit year to a two-digit year. I am not seeing anything on the DateTime object. Or should I just keep processing it as I am?

© Stack Overflow or respective owner

Related posts about c#

Related posts about datetime