Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Month name from integer

Month name from integer

Scheduled Pinned Locked Moved C#
question
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G GISnet

    I don't really know if there is a built-in function (I looked in System.DateTime but didn't see one) so I threw this one together: private string MonthName(int iMonth) { string[] sMonths = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return sMonths[iMonth] ; }

    U Offline
    U Offline
    Uncle Monkey
    wrote on last edited by
    #3

    thanks for that GISnet. I didn't see one either and wondered if I'd missed something really obvious and was being stoopid :wtf: It ain't what you know that matters. U.M.

    1 Reply Last reply
    0
    • U Uncle Monkey

      I have an integer representing a month, what is the best way to convert it into the full month name? thanks U.M. It ain't what you know that matters. Uncle Monkey

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #4

      System.Globalization.DateTimeFormatInfo.MonthNames

      G 1 Reply Last reply
      0
      • N Not Active

        System.Globalization.DateTimeFormatInfo.MonthNames

        G Offline
        G Offline
        GISnet
        wrote on last edited by
        #5

        Ok now I feel :(( .

        1 Reply Last reply
        0
        • U Uncle Monkey

          I have an integer representing a month, what is the best way to convert it into the full month name? thanks U.M. It ain't what you know that matters. Uncle Monkey

          J Offline
          J Offline
          Jim Stewart
          wrote on last edited by
          #6

          Here is my contribution:

          public enum Months
          {
          January = 1,
          February,
          March,
          April,
          May,
          June,
          July,
          August,
          September,
          October,
          November,
          December
          };

          [STAThread]
          static void Main(string[] args)
          {
          for (Months month = Months.January; month <= Months.December; month++)
          Console.WriteLine ("{0} - {1}", (int)month, month.ToString ());
          }

          α.γεεκ

          Fortune passes everywhere.
          Duke Leto Atreides

          D 1 Reply Last reply
          0
          • J Jim Stewart

            Here is my contribution:

            public enum Months
            {
            January = 1,
            February,
            March,
            April,
            May,
            June,
            July,
            August,
            September,
            October,
            November,
            December
            };

            [STAThread]
            static void Main(string[] args)
            {
            for (Months month = Months.January; month <= Months.December; month++)
            Console.WriteLine ("{0} - {1}", (int)month, month.ToString ());
            }

            α.γεεκ

            Fortune passes everywhere.
            Duke Leto Atreides

            D Offline
            D Offline
            Daniel Turini
            wrote on last edited by
            #7

            Jim Stewart wrote: Here is my contribution: This has no international support... :(( ORACLE One Real A$#h%le Called Lary Ellison

            J 1 Reply Last reply
            0
            • D Daniel Turini

              Jim Stewart wrote: Here is my contribution: This has no international support... :(( ORACLE One Real A$#h%le Called Lary Ellison

              J Offline
              J Offline
              Jim Stewart
              wrote on last edited by
              #8

              I respectfully submit that the problem description did not indicate the need for internationalization. Therefore my modest contribution met the initial requirements.
              Since the bar has been raised, I will attempt to satisfy.
              One solution might go thus:

              public enum Mois
              {
              Janvier = 1,
              Février,
              Mars,
              Avril,
              Peut,
              Juin,
              Juillet,
              Août,
              Septembre,
              Octobre,
              Novembre,
              Décembre
              };
              [STAThread]
              static void Main(string[] args)
              {
              for (Mois mois = Mois.Janvier; mois <= Mois.Décembre; mois++)
              {
              Console.WriteLine (mois.ToString ());
              }
              }

              I suspect that this is not what was intended. So to blend my previous solution with Monsieur Nischalke:

              public enum Months
              {
              January,
              February,
              March,
              April,
              May,
              June,
              July,
              August,
              September,
              October,
              November,
              December
              };
              [STAThread]
              static void Main(string[] args)
              {
              DateTimeFormatInfo dtfi = new DateTimeFormatInfo ();
              for (Months month = Months.January; month <= Months.December; month++)
              {
              Console.WriteLine (dtfi.MonthNames[(int)month]);
              }
              }

              This has the benefit of symbolic constants instead of literals with the internationalization.

              α.γεεκ

              Fortune passes everywhere.
              Duke Leto Atreides

              N 1 Reply Last reply
              0
              • J Jim Stewart

                I respectfully submit that the problem description did not indicate the need for internationalization. Therefore my modest contribution met the initial requirements.
                Since the bar has been raised, I will attempt to satisfy.
                One solution might go thus:

                public enum Mois
                {
                Janvier = 1,
                Février,
                Mars,
                Avril,
                Peut,
                Juin,
                Juillet,
                Août,
                Septembre,
                Octobre,
                Novembre,
                Décembre
                };
                [STAThread]
                static void Main(string[] args)
                {
                for (Mois mois = Mois.Janvier; mois <= Mois.Décembre; mois++)
                {
                Console.WriteLine (mois.ToString ());
                }
                }

                I suspect that this is not what was intended. So to blend my previous solution with Monsieur Nischalke:

                public enum Months
                {
                January,
                February,
                March,
                April,
                May,
                June,
                July,
                August,
                September,
                October,
                November,
                December
                };
                [STAThread]
                static void Main(string[] args)
                {
                DateTimeFormatInfo dtfi = new DateTimeFormatInfo ();
                for (Months month = Months.January; month <= Months.December; month++)
                {
                Console.WriteLine (dtfi.MonthNames[(int)month]);
                }
                }

                This has the benefit of symbolic constants instead of literals with the internationalization.

                α.γεεκ

                Fortune passes everywhere.
                Duke Leto Atreides

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #9

                Since the gauntlet of challenge has been thrown. using System.Globalization; CultureInfo ci = new CultureInfo("fr-FR", true); DateTimeFormatInfo di = ci.DateTimeFormat; foreach(string strMonth in di.MonthNames) Console.WriteLine(strMonth);

                J 1 Reply Last reply
                0
                • N Not Active

                  Since the gauntlet of challenge has been thrown. using System.Globalization; CultureInfo ci = new CultureInfo("fr-FR", true); DateTimeFormatInfo di = ci.DateTimeFormat; foreach(string strMonth in di.MonthNames) Console.WriteLine(strMonth);

                  J Offline
                  J Offline
                  Jim Stewart
                  wrote on last edited by
                  #10

                  May I ask how one gets the month name from an integer in this scenario?

                  α.γεεκ

                  Fortune passes everywhere.
                  Duke Leto Atreides

                  N 1 Reply Last reply
                  0
                  • J Jim Stewart

                    May I ask how one gets the month name from an integer in this scenario?

                    α.γεεκ

                    Fortune passes everywhere.
                    Duke Leto Atreides

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #11

                    DateTimeFormatInfo.MonthNames Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months.

                    J 1 Reply Last reply
                    0
                    • N Not Active

                      DateTimeFormatInfo.MonthNames Gets or sets a one-dimensional array of type String containing the culture-specific full names of the months.

                      J Offline
                      J Offline
                      Jim Stewart
                      wrote on last edited by
                      #12

                      Touche - I was getting a bit punchy last night.

                      α.γεεκ

                      Fortune passes everywhere.
                      Duke Leto Atreides

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups