0

I am getting date as string parameter that is ExpDate as 12/16(month/year), i need to convert it as DateTime and save it to the sql db, i convert the above string to date as

paymentMethod.ExpirationDate = Convert.ToDateTime(ExpDate);

this absolutely working in my machine and saved in my db. but this is throws an error in my colleague's machine as

String was not recognized as a valid DateTime.

i have googled it and i come to know that i need to do cultureinfo. but i am getting the date as MM/yy only that is why i cant go through it. can anyone tell what do i need to do here?

1 Answers1

0

You should use this overload: https://msdn.microsoft.com/ru-ru/library/kc8s65zs(v=vs.110).aspx

paymentMethod.ExpirationDate = DateTime.Parse(ExpDate, CultureInfo.CurrentCulture);
zabulus
  • 2,373
  • 3
  • 15
  • 27
  • it's not working though, please consider my date string is month and year only like 12/16 –  May 21 '16 at 06:43
  • This is what i required **paymentMethod.ExpirationDate = DateTime.ParseExact(ExpDate, "MM/yy", System.Globalization.CultureInfo.CurrentCulture);** thanks for the info... –  May 26 '16 at 16:10