C# 24 hour time?

  • Thread starter Thread starter Dogmar Hoffman
  • Start date Start date
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
 
Hi

Maybe try this:
System.DateTime MyDateTime = System.DateTime.Now;
MessageBox.Show(System.Convert.ToString(MyDateTime));
 
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");
 
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
 
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
 
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");
 
Back
Top