C# Format Date assigned to a string

I have a string which is storing a date value 10/30/2015 12:00:00 am.  I need to format it as 20151030.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This should suffice:
using System;

namespace EE_Q28791680
	class Program
		static void Main(string[] args)
			DateTime current = new DateTime(2015, 10, 30);
			Console.WriteLine("The new string representation for {0:MM/dd/yyyy} is {0:yyyyMMdd}", current);

Open in new window

Which produces the following output -Capture.JPGYou can read more about Custom Date/Time Formats from here:


käµfm³d 👽Commented:
*No Points*

I like the presentation of formatters as laid out on http://blog.stevex.net/string-formatting-in-csharp/
Chris StanyonWebDevCommented:
You'll need to convert your string to a DateTime object, and then format that:

String originalDate = "10/30/2015 12:00:00 am";
String format = "MM/dd/yyyy hh:mm:ss tt";
DateTime newDate = DateTime.ParseExact(originalDate, format, CultureInfo.InvariantCulture);


Open in new window

CipherISAuthor Commented:
I tried the above recommendations.  This was the solution that worked for me.

var row = new ExportRow
DispDate = String.Format("{0:yyyyMMdd}", Convert.ToDateTime(result.dispDate))

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CipherISAuthor Commented:
Was the solution that resolved my problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.