How can I convert a date time string to int format yyyyMMdd

countrymeister
countrymeister used Ask the Experts™
on
BusinessDate = 2012-09-27 00:00:00.000

Would like to convert to 20120927
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
DateTime dte = new DateTime(2012,09,27,0,0,0);
            String s = dte.ToString("yyyyMMdd");
//s is 20120927
Retired
Distinguished Expert 2017
Commented:
Hi countrymeister;

This will do what you need.

string dtStr = "2012-09-27 00:00:00.000";

string date = DateTime.Parse(dtStr).ToString("yyyyMMdd");

Open in new window

AndyAinscowFreelance programmer / Consultant

Commented:
Aha - the question really was how to convert a string into a datetime.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial