Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Credit card expiration date

Posted on 2014-10-14
6
273 Views
Last Modified: 2016-02-17
Hello,
Credit card expiration date  - I want fill the drop down with MM/YY format

for e.g:

10/14
11/14
12/14
01/15
02/15
and so on... for next 10 or 12 years..


I am using C# /asp.net.  Any idea?


Thanks
0
Comment
Question by:mani_sai
6 Comments
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 200 total points
ID: 40380274
two loops should do it.  Note that this was coded by hand so there may be a couple of compiler errors.

int m = DateTime.Now.Month;

for (int y = DateTime.Now.Year; y <= DateTime.Now.Year + 12; y++)
{
  while (m <= 12)
  {
     string val = String.Format("{0:D2}/{1}", m, y.ToString().Substring(2,2));   
    //add val to dropdown list.
    m++;
  }
   m = 1;
}

Open in new window

0
 
LVL 8

Author Comment

by:mani_sai
ID: 40380281
Thanks
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 40380319
..why not just have two dropdowns?  ..usually it's one dropdown for months, one for years.. on most websites.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 100 total points
ID: 40380521
Here's an alternative without the need for 2 loops - just use the AddMonths() method:

DateTime expiryDate = DateTime.Today;

// Loop through for 36 months
for (int i = 0; i < 36; i++)
{
	// Add the value to your dropdown
	comboBoxExpiryDate.Items.Add((object)expiryDate.ToString("MM/yy"));
	
	// Add a month
	expiryDate = expiryDate.AddMonths(1);
}

Open in new window

0
 
LVL 33

Accepted Solution

by:
it_saige earned 200 total points
ID: 40380677
And here is an example that uses linq:
foreach (var cc in (from d in Enumerable.Range(0, 144) let now = DateTime.Now.AddMonths(d) select now.ToString("MM/yy")))
	comboBoxExpiryDate.Items.Add(cc);

Open in new window


-saige-
0
 
LVL 8

Author Comment

by:mani_sai
ID: 40382237
Thanks to all of you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question