How to make a DataTime object from a string?

Q

Quentin Huo

Hi:

I have a string which value has the date format, like

"Wed, 15 Sep 2004 15:52:36 GMT",

and I want to create an object of DateTime, like:

DateTime dt = (DateTime)(theDateString);

But it doesn't work.

How can I do this?

Thanks

Q.
 
N

Nicholas Paldino [.NET/C# MVP]

Quentin,

You can't just use a cast. Pass the string to the static Parse methd or
to the ParseExact method, like this:

DateTime dt = DateTime.Parse(theDateString);

Hope this helps.
 
S

Shiva

Hi,

Try DateTime.Parse() as in

DateTime dt = DateTime.Parse ("Wed, 15 Sep 2004 15:52:36 GMT");
Console.WriteLine (dt.ToString());

Hi:

I have a string which value has the date format, like

"Wed, 15 Sep 2004 15:52:36 GMT",

and I want to create an object of DateTime, like:

DateTime dt = (DateTime)(theDateString);

But it doesn't work.

How can I do this?

Thanks

Q.
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top