Parse not recognizing date even with cultureinfo "15 ene 2013" ad "15/01/2013"

I have an input day of “15 ene 2013” (Enero is January in spanish), i’m trying to parse it with:

DateTime.ParseExact(strRawDate,“dd MMM yyyy”,System.Globalization.CultureInfo.CreateSpecificCulture(“es-ES”)).ToString(“dd/MM/yyyy”)

This should correctly read “15 ene 2013” and output “15/01/2013”

This worked correctly until around a month ago but hasn’t worked since, it says that “the string was not recognized a valid datetime”.
To note, it also doesn’t work with “Ene” in caps.
Also i cant use “invariant culture” as i need it to recognize “ene” as “Enero”.

Hi @david.arenas

How about the following?

DateTime.ParseExact(Input, {"dd MMM yyyy", "dd MMMM yyyy", "d MMM yyyy", "d MMMM yyyy", "dd 'ene' yyyy", "d 'ene' yyyy"}, System.Globalization.CultureInfo.CreateSpecificCulture("es-ES").DateTimeFormat, System.Globalization.DateTimeStyles.None).ToString("dd/MM/yyyy")

or

New DateTime(Integer.Parse(Input.Split(" ")(2)), _
                   Array.IndexOf(New String() {"ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic"}, Input.Split(" ")(1)) + 1, _
                   Integer.Parse(Input.Split(" ")(0))).ToString("dd/MM/yyyy")

Cheers!!

1 Like

Thanks!, i ended up doing something very close to that second option and worked like a charm and for every month!

1 Like

Not daily but time by time this question and surprises occurs

a spanish CultureInfo has the following Abbreviated month names:
grafik

So MMM - for abbreviated can also be longer then 3 chars

So we fail:
grafik

but have success with:
grafik
as input Month is as defined

We also see, that it is case insensitive
grafik

So with this relation in mind there are several workarounds available.

One of many with the benefit of not touching the input value /when we assume that never a dot occurs could be the following:

customizing the CI

And we can do:
grafik

There are also other specific CultureInfos with the same topic of more then 3 chars long MMM
grafik

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.