Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-12-30
3
Medium Priority
?
2,506 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 1000 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 1000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 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