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!
string sDate = list[x].StartDate.ToString
sDate = String.Format("{0:ddd, MMM d, yyyy}", sDate);
Thanks!
How do you display it? In what control; perhaps via a message box?
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
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:
With your format it would look like this:
string sDate = list[x].StartDate.ToString("ddd, MMM d, yyyy");