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”.
lrtetala
(Lakshman Reddy)
January 25, 2024, 5:29pm
3
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
ppr
(Peter Preuss)
January 25, 2024, 8:07pm
5
Not daily but time by time this question and surprises occurs
a spanish CultureInfo has the following Abbreviated month names:
So MMM - for abbreviated can also be longer then 3 chars
So we fail:
but have success with:
as input Month is as defined
We also see, that it is case insensitive
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:
There are also other specific CultureInfos with the same topic of more then 3 chars long MMM
system
(system)
Closed
January 28, 2024, 8:07pm
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.