473,378 Members | 1,413 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,378 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 16 '05 #1
3 2545
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 16 '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 16 '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 16 '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();
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.