Format Date tagged posts

Format Of Date Function in Asp.net

Category: ASP.NETC#.Net Comments: No comments

Steps for Date Function in Asp.net

//Call this Function Where you need
// Pass your  date to FormatDate function
public string FormatDate(DateTime dt)
{
int date = dt.Day, month = dt.Month, year = dt.Year;
string mon = GetStringMonth(month);
return string.Format(“{0}-{1}-{2}”, mon, date.ToString(), year.ToString());
}

public string GetStringMonth(int mon)
{
string name = “”;
switch (mon)
{
case 1: name = “JAN”; break;
case 2: name = “FEB”; break;
case 3: name = “MAR”; break;
case 4: name = “APR”; break;
case 5: name = “MAY”; break;
case 6: name = “JUN”; break;
case 7: name = “JUL”; break;
case 8: name = “AUG”; break;
case 9: name = “SEP”; break;
case 10: name = “OCT”; break;
case 11: name = “NOV”; break;
case 12: name = “DEC”; break;
}
return name;
}

Ex:  .cs Page

textDate.text = Convert.ToString(FormatDate(DateTime.Now()));
OutPut = JAN-30-2013

Read More