By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,996 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,996 IT Pros & Developers. It's quick & easy.

C# 24 hour time?

P: n/a
Hello,

I am trying to use tostring to convert to a 24 hour time format, but am
getting the error "No Overload for Method 'ToString'takes '1'
arguments".

The following is what I have and it seems that this should function:

NewEvent.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString("HH/mm/ss"));

Am I missing something here? Thank you very much.

DH

*** Sent via Developersdex http://www.developersdex.com ***
Mar 29 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi

Maybe try this:
System.DateTime MyDateTime = System.DateTime.Now;
MessageBox.Show(System.Convert.ToString(MyDateTime ));

"Dogmar Hoffman" wrote:
Hello,

I am trying to use tostring to convert to a 24 hour time format, but am
getting the error "No Overload for Method 'ToString'takes '1'
arguments".

The following is what I have and it seems that this should function:

NewEvent.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString("HH/mm/ss"));

Am I missing something here? Thank you very much.

DH

*** Sent via Developersdex http://www.developersdex.com ***

Mar 29 '06 #2

P: n/a
Dogmar Hoffman <it******@itbranch.com> wrote:
I am trying to use tostring to convert to a 24 hour time format, but am
getting the error "No Overload for Method 'ToString'takes '1'
arguments".

The following is what I have and it seems that this should function:

NewEvent.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString("HH/mm/ss"));

Am I missing something here? Thank you very much.


You're calling ToString *within* the Parse, instead of after it. You
want:

NewEvent.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME]).ToString("HH/mm/ss");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #3

P: n/a
Thank you very much for the reply.

I have made the change, but now it says that it can not convert an obect
to a string. I do not get this error with:

NewProcess.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString());

just with:

NewProcess.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME]).ToString("HH/mm/ss");

Is there a difference in the way that C# treats ToString() for 24 hour
format? Thank you again!

DH

*** Sent via Developersdex http://www.developersdex.com ***
Mar 29 '06 #4

P: n/a
> Hello,

I am trying to use tostring to convert to a 24 hour time format, but am
getting the error "No Overload for Method 'ToString'takes '1'
arguments".

The following is what I have and it seems that this should function:

NewEvent.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString("HH/mm/ss"));

Am I missing something here? Thank you very much.

DH

*** Sent via Developersdex http://www.developersdex.com ***


If you are sure drCurProcess[COL_TPDATETIME] contains a valid date
(and not DbNull.Value or an invalid date - like MySql can store), then
you can cast:

NewEvent.TPDateTime = (DateTime)drCurProcess[COL_TPDATETIME];
Hans Kesting
Mar 29 '06 #5

P: n/a

Perfect. All is working . Thank you very much.

DH
*** Sent via Developersdex http://www.developersdex.com ***
Mar 29 '06 #6

P: n/a
Hi,

Out of curiosity, what is the type of TPDateTime ?
what is the type and value of drCurProcess[COL_TPDATETIME] ?

try:

NewProcess.TPDateTime = DateTime.Parse(
drCurProcess[COL_TPDATETIME].ToString() ).ToString("HH/mm/ss");
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dogmar Hoffman" <it******@itbranch.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
Thank you very much for the reply.

I have made the change, but now it says that it can not convert an obect
to a string. I do not get this error with:

NewProcess.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME].ToString());

just with:

NewProcess.TPDateTime =
DateTime.Parse(drCurProcess[COL_TPDATETIME]).ToString("HH/mm/ss");

Is there a difference in the way that C# treats ToString() for 24 hour
format? Thank you again!

DH

*** Sent via Developersdex http://www.developersdex.com ***

Mar 29 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.