How to make a DataTime object from a string?

  • Thread starter Thread starter Quentin Huo
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top