0

enter image description hereI want to parse this date "27-Jun-2118". I don't know why my code is not parsing this date. After looking around. I found out that it depends on Culture but I was unable to find out maximum date i can parse and more about culture.

string endDatep = "27-Jun-2118";
var provider = CultureInfo.InvariantCulture;
DateTime endDate;
var isEndDateParsed = DateTime.TryParseExact(endDatep, "dd-MMM-yyyy", provider, DateTimeStyles.None,out endDate);

I live in Pakistan.

Solution(not the reason)

Changing endDatep to Upper Case such that Jun becomes JUN solved the problem

Charlie
  • 4,827
  • 2
  • 31
  • 55
  • 2
    @Charlie: but that doesn't explain this issue. The code you have posted uses `InvariantCulture`, so it should not be necessary to use `JUN` instead of `Jun`(both work). Have you fixed above code or the original code which might be different? By the way, i have also tried to use `System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("ur-PK");` to reproduce the issue with no avail. – Tim Schmelter Jun 27 '18 at 12:05
  • Did trying `endDatep = "27-Jun-2118";` as the first line of the action also work? – mjwills Jun 27 '18 at 12:05
  • 1
    I won't answer unless I fully understand what's going on. It is not case sensitive when using `InvariantCulture`. so if my previous comment with Jun vs. JUN really solved your issue, we would need a mvce to prove, or something like a referencesource link that could explain it. – Cee McSharpface Jun 27 '18 at 12:42
  • confirmed that the comparison of month abbreviations is definitely [always case-insensitive](https://referencesource.microsoft.com/#mscorlib/system/globalization/datetimeparse.cs,4528). but there are some [intriguing bits](https://referencesource.microsoft.com/#mscorlib/system/globalization/datetimeparse.cs,3049) in that parser code. none apply here since `dtfi` will be `InvariantCulture` throughout. – Cee McSharpface Jun 27 '18 at 12:51
  • We're still missing a [mcve] that demonstrates the problem. With that, we'd be in a much better position to help you. – Jon Skeet Jun 28 '18 at 07:55

0 Answers0