Month As Integer Format to String?

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Dim iMonth As Integer = 1
Dim strMonth As String = Format(iMonth, "MMMM")
console.write(strMonth)

Output = "MMMM" expected "January"???

what should the code be?
 
Dim iMonth As Integer = 1
Dim strMonth As String = Format(iMonth, "MMMM")
console.write(strMonth)

Output = "MMMM" expected "January"???

what should the code be?

Option Strict On
Option Explicit On

Imports System.Globalization

Module modMain

Sub Main()
Dim Month As Integer = 1
Dim dfi As New DateTimeFormatInfo()

Console.WriteLine(dfi.MonthNames(Month))
End Sub
End Module

Or....

Dim Month As New Date(2003, 1, 1)
Console.WriteLine(Format(Month, "MMMM"))
 
Dave said:
Dim iMonth As Integer = 1
Dim strMonth As String = Format(iMonth, "MMMM")
console.write(strMonth)

Output = "MMMM" expected "January"???

what should the code be?

If you use "MMMM" as the format, the type of the passed value must be Date.
An Integer values does not contain a month part. :)

Instead:

strmonth =
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(
i)
 
Armin Zingler said:
strmonth =
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(
i)

Apart from Tom's suggestion,

System.Globalization.DateTimeFormatInfo.CurrentInfo

is shorter. :-/
 
Back
Top