Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am logging user actions throughout my program using datetime in the format hh:mm:ss:ff. I would like to calculate the difference between two times. Here is what I'm using for code:

 

Dim Time As Date

Time = DateTime.Now

Dim TaskTime As TimeSpan = Time.Subtract(AddMainBTime)

LogWriter.WriteLine("*TaskTime " & (TaskTime.ToString))

 

This works great, but I cannot figure out how to format the TaskTime to hh:mm:ss:ff. Right now, it writes to the file as hh:mm:ss.fffffff. When I try the following, I get the following error: 'Public Overrides Overloads Function ToString() As String' has no parameters and its return type cannot be indexed.

 

LogWriter.WriteLine("*TaskTime " & (TaskTime.ToString("hh:mm:ss:ff")))

 

Any ideas on how I can format my TimeSpan value? Thanks. :)

Posted

You can break a string down using LEFT and RIGHT facilities, i cant remember the exact context for this, but i think this should give u an idea.

 

MsgBox(Microsoft.VisualBasic.Left("hello", 3))

MsgBox(Microsoft.VisualBasic.Right("hello", 3))

 

SHOULD return the value "hel" and "llo", you can use this to break the dates down, and remove the annoying 20 out of 2003, or pretty much anything else - obviously you can also embed them into each other.

Posted

Thanks so much for your help. Here is how I resolved the situation:

 

LogWriter.WriteLine("*TaskTime " & (Microsoft.VisualBasic.Left(TaskTime.ToString, 11)))

 

Thank you!!!

  • *Experts*
Posted

You should stay away from Left and Right, in general. The string object supports a Substring method which does everything you need. Try this instead:

LogWriter.WriteLine("*TaskTime " & TaskTime.ToString().Substring(11))

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...