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

Get month name?

P: n/a
I can't find a way to obtain the months name from a date.
Like 'August'
Jul 31 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Edwin,

System.Globalization.DateTimeFormatInfo d = new
System.Globalization.DateTimeFormatInfo();

string month = d.MonthNames[DateTime.Now.Month];
On Mon, 31 Jul 2006 10:55:01 +0200, Edwin Knoppert <ne**@hellobasic.com>
wrote:
I can't find a way to obtain the months name from a date.
Like 'August'



--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 31 '06 #2

P: n/a
Thanks it works however, how to use it without the culture thing?
My web.config already has the dutch culture.

DateTimeFormatInfo d = new CultureInfo("nl-NL", false).DateTimeFormat;
sVorigeMaand = d.MonthNames[DateTime.Now.AddMonths(-1).Month];

:)
"Morten Wennevik" <Mo************@hotmail.comschreef in bericht
news:op***************@tr024.bouvet.no...
Hi Edwin,

System.Globalization.DateTimeFormatInfo d = new
System.Globalization.DateTimeFormatInfo();

string month = d.MonthNames[DateTime.Now.Month];
On Mon, 31 Jul 2006 10:55:01 +0200, Edwin Knoppert <ne**@hellobasic.com>
wrote:
I can't find a way to obtain the months name from a date.
Like 'August'



--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 31 '06 #3

P: n/a
Got it :)

sVorigeMaand =
DateTimeFormatInfo.CurrentInfo.MonthNames[DateTime.Now.AddMonths(-1).Month];
"Edwin Knoppert" <ne**@hellobasic.comschreef in bericht
news:44**********************@text.nova.planet.nl. ..
Thanks it works however, how to use it without the culture thing?
My web.config already has the dutch culture.

DateTimeFormatInfo d = new CultureInfo("nl-NL", false).DateTimeFormat;
sVorigeMaand = d.MonthNames[DateTime.Now.AddMonths(-1).Month];

:)
"Morten Wennevik" <Mo************@hotmail.comschreef in bericht
news:op***************@tr024.bouvet.no...
Hi Edwin,

System.Globalization.DateTimeFormatInfo d = new
System.Globalization.DateTimeFormatInfo();

string month = d.MonthNames[DateTime.Now.Month];
On Mon, 31 Jul 2006 10:55:01 +0200, Edwin Knoppert <ne**@hellobasic.com>
wrote:
>I can't find a way to obtain the months name from a date.
Like 'August'


--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 31 '06 #4

P: n/a
Warning, odd the items list starts from 0 but has a 13th item..

This is actually the current month!
sMaand =
DateTimeFormatInfo.CurrentInfo.MonthNames[DateTime.Now.AddMonths(-1).Month];

"Edwin Knoppert" <ne**@hellobasic.comschreef in bericht
news:44**********************@text.nova.planet.nl. ..
Thanks it works however, how to use it without the culture thing?
My web.config already has the dutch culture.

DateTimeFormatInfo d = new CultureInfo("nl-NL", false).DateTimeFormat;
sVorigeMaand = d.MonthNames[DateTime.Now.AddMonths(-1).Month];

:)
"Morten Wennevik" <Mo************@hotmail.comschreef in bericht
news:op***************@tr024.bouvet.no...
Hi Edwin,

System.Globalization.DateTimeFormatInfo d = new
System.Globalization.DateTimeFormatInfo();

string month = d.MonthNames[DateTime.Now.Month];
On Mon, 31 Jul 2006 10:55:01 +0200, Edwin Knoppert <ne**@hellobasic.com>
wrote:
>I can't find a way to obtain the months name from a date.
Like 'August'


--
Happy Coding!
Morten Wennevik [C# MVP]

Jul 31 '06 #5

P: n/a
"Edwin Knoppert" <ne**@hellobasic.comwrote in message
news:44**********************@text.nova.planet.nl. ..
DateTimeFormatInfo d = new CultureInfo("nl-NL", false).DateTimeFormat;
This is unnecessary in this instance...
sVorigeMaand = d.MonthNames[DateTime.Now.AddMonths(-1).Month];
sVorigeMaand = DateTime.Now.AddMonths(-1).ToString("MMMM");
Jul 31 '06 #6

P: n/a
Hah!
Before i tried M and MM but failed :)
"Mark Rae" <ma**@markNOSPAMrae.comschreef in bericht
news:e2*************@TK2MSFTNGP06.phx.gbl...
"Edwin Knoppert" <ne**@hellobasic.comwrote in message
news:44**********************@text.nova.planet.nl. ..
>DateTimeFormatInfo d = new CultureInfo("nl-NL", false).DateTimeFormat;
This is unnecessary in this instance...
>sVorigeMaand = d.MonthNames[DateTime.Now.AddMonths(-1).Month];
sVorigeMaand = DateTime.Now.AddMonths(-1).ToString("MMMM");

Jul 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.