Link to home
Start Free TrialLog in
Avatar of Sheryl Landis
Sheryl Landis

asked on

c# 2012 Format date from List

How do I format the date in this scenario?  The format string doesn't work and I've tried others.

string sDate = list[x].StartDate.ToString();
sDate = String.Format("{0:ddd, MMM d, yyyy}", sDate);

Thanks!
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

How do you display it? In what control; perhaps via a message box?
Avatar of Pratima
You can try something like this.

DateTime thisDate1 = new DateTime(2011, 6, 10);
Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy") + ".");
for exact answer please share what you are getting in string sDate
which will help us to understand what is required
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sheryl Landis
Sheryl Landis

ASKER

Here is what worked, and your solution prompted me to try it this way:

string sDate = String.Format("{0:ddd, MMM d, yyyy}", list[x].StartDate);

Before, I was converting StartDate .ToString() first, which didn't work:

string sDate = String.Format("{0:ddd, MMM d, yyyy}", list[x].StartDate.ToString());

Thank you all for your input!
Just use ToString() directly on the StartDate as alluded to by Pratima Pharande in the previous post back here.

With your format it would look like this:
string sDate = list[x].StartDate.ToString("ddd, MMM d, yyyy");

Open in new window