Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2005

Tip: Looking for answers? Try searching our database.

list of months and days for each month

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Abraham Andres Luna - 22 Sep 2005 18:49 GMT
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
CT - 23 Sep 2005 08:14 GMT
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.

Signature

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
John Bowman - 23 Sep 2005 13:49 GMT
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:
>
[quoted text clipped - 17 lines]
>> 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
CT - 23 Sep 2005 14:38 GMT
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");
        }

Signature

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

> Carsten,
>
[quoted text clipped - 24 lines]
>>> 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
John Bowman - 23 Sep 2005 17:07 GMT
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

> Something along these lines:
>
[quoted text clipped - 40 lines]
>>>> number of days for each month i was hoping it was already in .net.
>>>> thank you
CT - 23 Sep 2005 17:59 GMT
Yes, there seems to be multiple ways of doing most things in .NET. Great,
isn't it? :-)

Signature

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

> Carsten,
>
[quoted text clipped - 66 lines]
>>>>> number of days for each month i was hoping it was already in .net.
>>>>> thank you

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.