What is the best way to parse this string?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

orderDate = ("2004-12-08 00:00:00.000");

I want it to look like this:

string aMO = ("12");
string aDY = ("08");
string aYR = ("2004");

thanks,
Trint
 
check out the System.DateTime class, it has two methods:

DateTime.Parse
DateTime.ParseExact

HTH

Ollie Riches
 
DateTime orderDate=DateTime.Parse("2004-12-08 00:00:00.000");
string aMO=orderDate.Day.ToString();
string aDY=orderDate.Month.ToString();
string aYR=orderDate.Year.ToString();

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
You can use orderDate.Substring(startIndex, length) to extract portions of
it...

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
orderDate = ("2004-12-08 00:00:00.000");
I want it to look like this:
string aMO = orderDate.SubString(5,2);
string aDY = orderDate.SubString(0,4);
string aYR = orderDate.SubString((8,2;

I hope this helps

Cor
 
The most flexible method would be using Regular Expressions...
 
Cor,
I get this error:
'string' does not contain a definition for substing
thanks,
Trint
 
Cor,
You were right except SubString is really Substring.
Thanks...this worked.
Trint
 
Hi,

Try Substring instead and maybe a little common sense too ;)

cheers,
 
Ignacio,

I saw my error direct when I saw your message (was after sending mine),
however, had to go and thought as you wrote it in your answer
............................

Thanks,

:-)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top