Get name of month or day in C# and VB.Net

The DateTime structure in .Net is very useful and powerful for many purposes. It’s one of those basic classes you get in every programming language to be able to do whatever you need with dates. For example, print out a string of the current date in a certain format by the current culture standards:



The whole list of format options has been summed up at the ‘Custom Date and Time Format Strings‘ msdn page.

But sometimes you only have need for the name of the month or the day in the current culture and you have the integer value for these. You can create a whole DateTime object which situates in the given month. But I dislike doing that step because I don’t need it. I don’t require to have the rest of the date properties nor do I need to do calculations. It’s overhead in my eyes. After a bit of searching, I came to these alternatives:

This works exactly the same in VB.Net as well. ‘CultureInfo.CurrentCulture.DateTimeFormat’ returns a DateTimeFormatInfo object which you can use to get localized format information for the current culture.

In VB.Net you also have the MonthName and WeekdayName global functions, which do exactly the same as above. But even a lot shorter:

Leave a Reply

Your email address will not be published. Required fields are marked *