tags:

views:

859

answers:

4

Trying to do the following:

order.ExpirationDate =(DateTime) ( ExpMonth + "/" + ExpYear);

ExpMonth, Expyear are both ints.

+11  A: 

This is going to be better for you:

order.ExpirationDate = new DateTime(ExpYear, ExpMonth, 1)
Keltex
+1 This is the better answer, I deleted mine.
Andrew Hare
A: 

You need to use:

DateTime.Parse(ExpMonth.ToString() + "/" + ExpYear.ToString());
Justin Niessner
A: 

Try this:

DateTime dt;
if (DateTime.TryParse(ExpMonth + "/" + ExpYear, out dt))
{
   // success
}
Pablo Santa Cruz
A: 

Try creating a new DateTime using the constructor which takes month and year as parameters (it also takes a day, but you can default to 1) instead of casting a string, it's much cleaner and easier.

Steve Haigh