Solved

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

Posted on 2012-12-30
3
2,400 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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