Date Formates


Convert Date in User Define formate

Convert Date in User Define formate



Following function converts date in below formate
ex.
i want to convert date in 8th June 2010
or 21st June 2010
or 22nd June 2010
or 23rd June 2010



protected string ConvertDate()

{
string strMonth = string.Empty;
string strDayPostfix = string.Empty;
switch (DateTime.Now.Month)
{
case 1: strMonth = "January";
break;
case 2: strMonth = "February";
break;
case 3: strMonth = "March";
break;
case 4: strMonth = "April";
break;
case 5: strMonth = "May";
break;
case 6: strMonth = "June";
break;
case 7: strMonth = "July";
break;
case 8: strMonth = "August";
break;
case 9: strMonth = "September";
break;
case 10: strMonth = "October";
break;
case 11: strMonth = "November";
break;
case 12: strMonth = "December";
break;
default: break;
}

if (DateTime.Now.Day == 1 || DateTime.Now.Day == 21 || DateTime.Now.Day == 31)
{
strDayPostfix = "st";
}
else if (DateTime.Now.Day == 2 || DateTime.Now.Day == 22)
{
strDayPostfix = "nd";
}
else if (DateTime.Now.Day == 3 || DateTime.Now.Day == 23)
{
strDayPostfix = "rd";
}
else
{
strDayPostfix = "th";
}
return DateTime.Now.DayOfWeek.ToString() + " " + DateTime.Now.Day.ToString() + strDayPostfix + " " + strMonth + " " + DateTime.Now.Year.ToString();
}


Related Articles

SQL DATE Time Convert

During Sql Queries most of the time we need to manipulate the format of Date below I am trying to cover most of the format of date time in sql queries.

More articles: Date formatting Date Format Convert to date format Date and Time formats

Comments

No responses found. Be the first to comment...


  • 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: