Need help with Date format conversion using cultureInfo

Hi there,

I am trying to convert to dd/ MMM/ yy using German cultureInfo

For example: 28.12.2020 should become 28/ Dez/ 20

Right now I have the following variables setup:

germanDateTest as string
newDate as string
germanCulture as CultureInfo (Default value = New CultureInfo(“de-DE”))

I am using this for the conversion:

newDate = Datetime.ParseExact(germanDateTest.ToString,“”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd/ MMM/ yy”, germanCulture).Replace(".","/")

It doesn’t convert the month correctly for some reasons. It will just show 28/ Jan/ 20 no matter what I entered for the month.

Please let me know if you know what is causing this problem or you know a better way to archive this goal. Thanks!

try with MM instead of mm MM=Month, mm= minutes

Ah yes! That was a huge overlook on my part. It works perfectly now. Thank you very much!

Hi @ppr,

I am now facing a new problem.

Previously I had germanDateTest assigned to a hard coded date and everything works. But now I want to assign it to a string of values, and use an Array to split the date out, and then use the date conversion method that I had to convert the date.

So my setups look like this:

germanDateTest = “Copper|23. July 2020|6.533|6.510|143.800”

strArray_copper = germanDateTest.Split("|"c)

newDate = Datetime.ParseExact(strArray_copper(1).ToString,“dd. MMM yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd/ MMM/ yy”, germanCulture).Replace(".","/")

But now I am getting an error saying “String was not recognized as a valid DateTime.”

Any idea how to fix this?

@skyblue1854 Your data probably has a different date format, As I have noticed you Have July that is the Complete Month Name, maybe you can use this format and check “dd. MMMM yyyy”

Wow…Yep. I just keep overlooking small things like that. I think it might be time for me to take a break. I stared at it for too long. Thank you so much.

1 Like

In such a Case Debugging and Analysis is recommended.

Set a Breakpoint before the dateparsing and inspect the values in the local Panels. Also have Play in the watch Panel or immediate panel

1 Like

Very good tip. Thanks again!

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