Datetime.parseexact returns invalid month

Here is my code:

a.dateFrom = DateTime.ParseExact(x, "dd/mm/yyyy", null); 

And x matters: 03/08/2012

However, the value of a.dateFrom is 08/01/2012. Why?

+6
source share
2 answers

You must use MM as the format of the month.

+18
source

As ionden notes, you must have the format

 "dd/MM/yyyy" 

You are currently parsing the second part as minutes (as mm means).

See the documentation for custom date and time format strings for more information. I also highly recommend that you consider using an invariant culture for parsing - if you use a custom format string, it usually means that you don’t want to consider the input in a culture-sensitive style at all.

+5
source

Source: https://habr.com/ru/post/911743/


All Articles