You are explicitly telling the system to parse the date using US rules.
US dates are formatted as
M/d/yyyy
. Therefore, you are trying to parse value representing 9th
Smarch[
^] - the fictional thirteenth month, which doesn't exist.
The previous value "worked", in that it parsed the date. But it didn't give you what you were expecting: it would produce 4th August, not 8th April.
DateTime.TryParseExact
didn't work, because the format you've told it to parse doesn't match the format of the input. You've told it to parse
dd/mm/yyyy
, but the input is formatted as
dd/M/yyyy hh:mm:ss "πμ"
. If you change your code to:
DateTime.TryParseExact(dateString, "dd/M/yyyy hh:mm:ss \"πμ\"", CultureInfo.GetCultureInfo("en-US").DateTimeFormat, DateTimeStyles.None, out dtTarget)
it should parse successfully.
However, it would probably be easier to use the correct culture to parse the dates instead:
DateTime.TryParse(dateString, CultureInfo.GetCultureInfo("el-GR"), DateTimeStyles.None, out dtTarget)