Reputation: 28248
Trying to do the following:
order.ExpirationDate =(DateTime) ( ExpMonth + "/" + ExpYear);
ExpMonth, Expyear are both ints.
Upvotes: 1
Views: 6686
Reputation: 8511
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.
Upvotes: 0
Reputation: 181270
Try this:
DateTime dt;
if (DateTime.TryParse(ExpMonth + "/" + ExpYear, out dt))
{
// success
}
Upvotes: 0
Reputation: 245389
You need to use:
DateTime.Parse(ExpMonth.ToString() + "/" + ExpYear.ToString());
Upvotes: 0
Reputation: 26426
This is going to be better for you:
order.ExpirationDate = new DateTime(ExpYear, ExpMonth, 1)
Upvotes: 11