Solved

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

Posted on 2012-12-30
3
2,184 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
3 Comments
 
LVL 74

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 85

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now