Get month name?

  • Thread starter Thread starter Edwin Knoppert
  • Start date Start date
E

Edwin Knoppert

I can't find a way to obtain the months name from a date.
Like 'August'
 
Hi Edwin,

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

string month = d.MonthNames[DateTime.Now.Month];
 
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" <[email protected]> schreef in bericht
Hi Edwin,

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

string month = d.MonthNames[DateTime.Now.Month];
 
Got it :)

sVorigeMaand =
DateTimeFormatInfo.CurrentInfo.MonthNames[DateTime.Now.AddMonths(-1).Month];


Edwin Knoppert said:
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" <[email protected]> schreef in bericht
Hi Edwin,

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

string month = d.MonthNames[DateTime.Now.Month];


I can't find a way to obtain the months name from a date.
Like 'August'
 
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 said:
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" <[email protected]> schreef in bericht
Hi Edwin,

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

string month = d.MonthNames[DateTime.Now.Month];


I can't find a way to obtain the months name from a date.
Like 'August'
 
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");
 
Hah!
Before i tried M and MM but failed :)


Mark Rae said:
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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top