473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to make a DataTime object from a string?

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.

Nov 18 '05 #1
3 1142
DateTime.Parse

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #2
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #3
Hi,

Try DateTime.Parse() as in

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

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eb**************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sun | last post by:
Hi all, I am inserting datatime value into mysql table, while select value its giving 0000-00-00 00:00:00 value. mysql> insert into dtest values('02-17-05 17:08:02'); Query OK, 1 row...
8
by: Zibi | last post by:
I have some problem with datatime. SELECT * FROM stat WHERE data > '2005-05-24 14:07:28' ORDER BY id Asc I got the error: Microsoft OLE DB Provider for SQL Server error '80040e07' The...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
3
by: Quentin Huo | last post by:
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);
4
by: barry | last post by:
Hi does anyone know which format character i should use to get the the following date string 2006-01-30T22:00:00.0000000-08:00 if i use 's' format i get 2006-01-30T22:00:00
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
4
by: robinsand | last post by:
Header File: car.h #if !defined CAR_H #define CAR_H enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV }; class Car { public: Car();
8
by: padew | last post by:
I want make a vfariabl on the fly so: for (var i = 0; i<2; i++) { z+i=new Array("a"); fo to have: z0=a z1=a z1=a
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
3
by: =?Utf-8?B?QnJpYW4gUi4=?= | last post by:
We are working with a system (black box to us) that provides date/time in the following string format: "Tues Sep 30 15:16:41 PDT 2008" Where PDT is the local time zone. We need to parse...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.