By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Month As Integer Format to String?

P: n/a
Dim iMonth As Integer = 1
Dim strMonth As String = Format(iMonth, "MMMM")
console.write(strMonth)

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

what should the code be?

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <01****************************@phx.gbl>, Dave wrote:
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"))

--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 1 Build 2600
System Up Time: 19 Days, 8 Hours, 12 Minutes, 41 Seconds
Nov 20 '05 #2

P: n/a
"Dave" <an*******@discussions.microsoft.com> schrieb
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.Da teTimeFormat.GetMonthName(
i)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
strmonth =
System.Globalization.CultureInfo.CurrentCulture.Da teTimeFormat.GetMonthName( i)


Apart from Tom's suggestion,

System.Globalization.DateTimeFormatInfo.CurrentInf o

is shorter. :-/
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

P: n/a
Thanks for that.
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.