C# 24 hour time?

D

Dogmar Hoffman

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
 
G

Guest

Hi

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

Jon Skeet [C# MVP]

Dogmar Hoffman said:
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");
 
D

Dogmar Hoffman

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
 
H

Hans Kesting

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

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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");
 

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

Top