VB.NET Code to get the month name by passing the month value as integer from 1 to 12

The following sample VB.NET code demonstrates how to get a month name if month value is passed as integer from 1 to 12.


Private Function GetMonthName(ByVal monthNum As Integer) As String
Try
Dim strDate As New DateTime(1, monthNum, 1)
Return strDate.ToString("MMM")

Catch ex As Exception

End Try
End Function


Comments

Author: Rahul09 Feb 2009 Member Level: Silver   Points : 1

Hey Shantanu Thanks friend for submitting this function,it helps me very well..Thanks

Regards
Rahul

Author: Sasikumar18 Feb 2009 Member Level: Gold   Points : 0

Hi,

This above function works fine for me,

Thanks,
Sasikumar

Author: Babu Kumarasamy05 Jun 2009 Member Level: Gold   Points : 1

There is already an inbuilt function

http://www.plus2net.com/asp-tutorial/date-month.php

Author: Babu Kumarasamy05 Jun 2009 Member Level: Gold   Points : 1

There is already an inbuilt function

http://www.plus2net.com/asp-tutorial/date-month.php

Author: Vineet Yadav05 Apr 2010 Member Level: Bronze   Points : 1

You can use the following :

DateTime.Now.ToString("MMM")
"Apr"

DateTime.Now.ToString("MMMM")
"April"



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: