I’m trying to display the month from a datetime object in text so that it looks like this:
01 Dec 2011
I’ve created a switch statement to identify the month and put the string into a variable I want to display on my index.aspx page. However, it doesn’t seem to work and I’m not sure why.
<%
string month = "";
switch(item.postdate.Month)
{
case(1):
month = "Jan";
break;
case(2):
month = "Feb";
break;
case(3):
month = "Mar";
break;
case(4):
month = "Apr";
break;
case(5):
month = "Maj";
break;
case(6):
month = "jun";
break;
case(7):
month = "Jul";
break;
case(8):
month = "Aug";
break;
case(9):
month = "Sep";
break;
case(10):
month = "Okt";
break;
case(11):
month = "Nov";
break;
case(12):
month = "Dec";
break;
};
Html.Display(month);
%>
You could try:
Or if you just want the name in a string
More information about
DateTime.ToString()