This post is demonstrating how one can convert a DateTime to a full date as below:

DateTime Before:     15/01/2000  21:00:00

String Date After:        08:00pm Monday 15th January 2000

1. First add reference to:

using System.Globalization;

2. Then copy/paste and call the below methods to get full date as string.

protected string GetFullDate()
{

DateTime dateToConvert= DateTime.Now;  // dd/MM/yyyy 00:00:00  (15/01/2000 21:00:00)

string timeAsString = dateToConvert.ToString();
string timeOnly = Convert.ToDateTime(timeAsString).ToString(“hh:mmtt”,
CultureInfo.InvariantCulture).ToLower(); // 09:00 pm

string DateNoTime = now.ToString(“f”).Remove(now.ToString(“f”).Length – 5); // ddd dd Month Year (Monday 15 January 2000)
string FullDate = DateNoTime.Substring(0, 2) + CheckDayOfMonth(DateNoTime.Substring(0, 2)) + DateNoTime.Substring(2); //ddd ddth Month Year ( Monday 15th January 2000)

return timeOnly + ” ” + thisDate.DayOfWeek + ” ” + FullDate; //09:00pm Monday 15th January 2012

}

private string CheckDayOfMonth(string dd)
{

if (dd.Equals(“01”)) return “st”;
else if (dd.Equals(“02”)) return “nd”;
else if (dd.Equals(“03”)) return “rd”;
else return “th”;

}

3. Change the DateTime.Now to any date you would like to convert or add it as a parameter like this:

protected string GetFullDate(DateTime dateToConvert)
{

//The Above Method 

}

4. Modify as most suitable, for example: if you don’t need the time, remove timeOnly from the return statement.

 

Enjoy 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s