list of months and days for each month

  • Thread starter Thread starter Abraham Andres Luna
  • Start date Start date
A

Abraham Andres Luna

is there a way in .net to pull a list of months, and then pull a list of
days in the month. instead of retyping a control that lists the number of
days for each month i was hoping it was already in .net. thank you
 
For the months, you can do something like this:

Dim monthsFull(11) As String
Dim monthsAbbr(11) As String

For monthNumber As Integer = 1 To 12
' Get full month name
monthsFull(monthNumber - 1) = DateAndTime.MonthName(monthNumber)
' Get abbreviated month name
monthsAbbr(monthNumber - 1) = DateAndTime.MonthName(monthNumber, True)
Next

Please note that this is locale aware, i.e. it will return the localised
names, depedning on the regional settings on the system, on which you're
running the code. As to the days of the month, I'm not quite sure what you
mean. Check out the DataAndTime module, and in particular the Weekday and
WeekdayName functions.
 
Carsten,

Since C# does not have a DateAndTime object (but does have a DateTime) which
has a MonthName method, how could you do the same thing in C#?

John
 
Something along these lines:

string[] monthsFull = new string[12];
string[] monthsAbbr = new string[12];

for (int monthNumber = 1; monthNumber <= 12; monthNumber++)
{
// Get full month name
monthsFull[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMMM");
// Get abbreviated month name
monthsAbbr[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMM");
}
 
Carsten,

Thanks for the idea. I just found another way to retrieve the localized
Month names and the same approach works works for Days of the week too...

internal static string GetLocalizedMonthOfYear(int Month)
{
return
Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetMonthName(Month);
}

internal static string GetLocalizedDayOfWeek(int Day)
{
return
Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetDayName((DayOfWeek)Day);
}

With either your's or my approach, just change your Regional settings in
control panel, and viola, you get back the localized month for the language
you choose.


Thanks again,

John

CT said:
Something along these lines:

string[] monthsFull = new string[12];
string[] monthsAbbr = new string[12];

for (int monthNumber = 1; monthNumber <= 12; monthNumber++)
{
// Get full month name
monthsFull[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMMM");
// Get abbreviated month name
monthsAbbr[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMM");
}

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

John Bowman [email protected]> said:
Carsten,

Since C# does not have a DateAndTime object (but does have a DateTime)
which has a MonthName method, how could you do the same thing in C#?

John
 
Yes, there seems to be multiple ways of doing most things in .NET. Great,
isn't it? :-)

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

John Bowman [email protected]> said:
Carsten,

Thanks for the idea. I just found another way to retrieve the localized
Month names and the same approach works works for Days of the week too...

internal static string GetLocalizedMonthOfYear(int Month)
{
return
Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetMonthName(Month);
}

internal static string GetLocalizedDayOfWeek(int Day)
{
return
Thread.CurrentThread.CurrentCulture.DateTimeFormat.GetDayName((DayOfWeek)Day);
}

With either your's or my approach, just change your Regional settings in
control panel, and viola, you get back the localized month for the
language you choose.


Thanks again,

John

CT said:
Something along these lines:

string[] monthsFull = new string[12];
string[] monthsAbbr = new string[12];

for (int monthNumber = 1; monthNumber <= 12; monthNumber++)
{
// Get full month name
monthsFull[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMMM");
// Get abbreviated month name
monthsAbbr[monthNumber - 1] = new DateTime(1999, monthNumber,
1).ToString("MMM");
}

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

John Bowman [email protected]> said:
Carsten,

Since C# does not have a DateAndTime object (but does have a DateTime)
which has a MonthName method, how could you do the same thing in C#?

John


For the months, you can do something like this:

Dim monthsFull(11) As String
Dim monthsAbbr(11) As String

For monthNumber As Integer = 1 To 12
' Get full month name
monthsFull(monthNumber - 1) = DateAndTime.MonthName(monthNumber)
' Get abbreviated month name
monthsAbbr(monthNumber - 1) = DateAndTime.MonthName(monthNumber,
True)
Next

Please note that this is locale aware, i.e. it will return the
localised names, depedning on the regional settings on the system, on
which you're running the code. As to the days of the month, I'm not
quite sure what you mean. Check out the DataAndTime module, and in
particular the Weekday and WeekdayName functions.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

is there a way in .net to pull a list of months, and then pull a list
of days in the month. instead of retyping a control that lists the
number of days for each month i was hoping it was already in .net.
thank you
 
Back
Top