1

Below code throws an exception on my local, but not on server.

DateTime date = DateTime.ParseExact("01/06/2015", "dd/MM/yyyy", null);

Like I said it works on the server, but it throws 'System.FormatException' on my local. I assume this might be a problem of Cultural settings. However I don't know where I can look into.

Could anyone help me?

genki98
  • 680
  • 1
  • 11
  • 31
  • 1
    You may probably want to look into this similar thread: http://stackoverflow.com/questions/1368636/why-cant-datetime-parseexact-parse-9-1-2009-using-m-d-yyyy – TaoPR Jun 04 '15 at 02:47

1 Answers1

1

Try this:

DateTime date = DateTime.ParseExact("01/06/2015", "dd/MM/yyyy", CultureInfo.InvariantCulture);

If you don't specify the culture it will use whatever your current culture settings are. Since you know the format you should supply InvariantCulture.

Shaun Bowe
  • 9,840
  • 11
  • 50
  • 71