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:


Console.WriteLine(DateTime.Today.ToString("dd MMMM yyyy"));
 //Writes '06 april 2014' in nl-BE culture


Console.WriteLine(DateTime.Today.ToString("dd MMMM yyyy"))
'Returns the same as the C# code, so it's practically the same

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:


//Return 'april', the name of the month in the current culture
//Return 'apr', the abbreviation of the month in the current culture

//Return 'zondag', the weekday in the current culture
//Return 'zo', the abbreviation of the weekday in the current culture

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:


'Writes "april"
Console.WriteLine(MonthName(4, True))
'Writes "apr"

'Writes "zondag"
Console.WriteLine(WeekdayName(1, True))
'Writes "zo"