Wednesday, December 17, 2008

To get ShortMonth in C#.net

Hi,
Use the below coding to get the short month,
public static string GetShortMonth(object aDate)
{
DateTime actualDate = (DateTime)aDate;
int day = actualDate.Day;
int monthNumber = actualDate.Month;
string month = "";
if (monthNumber == 1)
{
month = "Jan,";
}
else if (monthNumber == 2)
{
month = "Feb,";
}
else if (monthNumber == 3)
{
month = "Mar,";
}
else if (monthNumber == 4)
{
month = "Apr,";
}
else if (monthNumber == 5)
{
month = "May,";
}
else if (monthNumber == 6)
{
month = "Jun,";
}
else if (monthNumber == 7)
{
month = "Jul,";
}
else if (monthNumber == 8)
{
month = "Aug,";
}
else if (monthNumber == 9)
{
month = "Sep,";
}
else if (monthNumber == 10)
{
month = "Oct,";
}
else if (monthNumber == 11)
{
month = "Nov,";
}
else if (monthNumber == 12)
{
month = "Dec,";
}
int year = actualDate.Year;
return month + " " + day.ToString() + " " + year.ToString();
}

No comments: