Convert Month number to short Month name

Hello everyone,

I have an excel sheet with a few columns. Every column starts with a specific month
Like this:

Now I want to convert the number from each month to the first three letters of each month
(7 → Jul, 8 → Aug)

I tried it like this:

  • read each cell and save it as “DTMN”
  • Str ShortMonth = DTMN.toString
    -ShortMonth = DateTime.ParseExact(ShortMonth, “MM”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MMM”)

But this code only works for month with two numbers (10, 11, 12)
For the other numbers I get the Error: String was not recognized as a valid DateTime

1 Like

@Loons
at least with PadLeft you can adopt
DateTime.ParseExact(“8”.PadLeft(2,"0"c), “MM”, System.Globalization.CultureInfo.InvariantCulture)

4 Likes

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