Solved

Need to convert integer to month name (English and French) in VB.Net

Posted on 2012-12-30
3
2,338 Views
Last Modified: 2012-12-31
Hi,

I need to convert a month integer into a month name, for both French and English, in VB.Net.

I would prefer to use some type of included Globalization parameters (such as CultureInfo.CreateSpecificCulture("fr-FR")) to do the conversion, rather than doing a "select case" and just listing all the month names in every language - since I may add a 3rd language soon to my site and want to keep my code clean.

For instance to format dates, I am currently using:

FrenchDate = mydatetime.ToString("dddd, 'le ' d MMMM yyyy, ' à ' h'h'mm", CultureInfo.CreateSpecificCulture("fr-FR"))

... but I cannot seem to find an equivalent I can use for an integer.

My integers are not preceeded by zeros (ie: they are 1,2,3,4,5,6,7,8,9,10,11,12) and I would like the full month name (ie: January or Janvier)

Thanks, Peter
0
Comment
Question by:pbissegger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 38731709
Just create a new DateTime instance that has the appropriate month set.

e.g.

mydatetime = New DateTime(DateTime.Now.Year, 1, DateTime.Now.Day)
mydatetime = New DateTime(DateTime.Now.Year, 3, DateTime.Now.Day)
mydatetime = New DateTime(DateTime.Now.Year, 5, DateTime.Now.Day)

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 38731809
Full example...using kaufmed's idea:
        Dim French As New Globalization.CultureInfo("fr-FR")
        Dim English As New Globalization.CultureInfo("en-US")

        For m As Integer = 1 To 12
            Dim dt As New DateTime(DateTime.Today.Year, m, 1)
            Debug.Print("English: " & dt.ToString("MMMM", English))
            Debug.Print("French: " & dt.ToString("MMMM", French))
        Next

Open in new window

0
 

Author Comment

by:pbissegger
ID: 38732456
It works ! Here is my final solution:

Function Monthonly(monthnumber as Integer) as String
        
        Dim French As New System.Globalization.CultureInfo("fr-FR")
        Dim English As New System.Globalization.CultureInfo("en-US")
        
        Dim dt As New DateTime(DateTime.Today.Year, monthnumber, 1)

        If Session("lang") = "english" Then
            Monthonly = dt.ToString("MMMM", English)
        else
            Monthonly = dt.ToString("MMMM", French)
        End If

End Function

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question