Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Trying to get a simple "HH:MM:SS" (in STRING format)

 

from the difference of these two datetime formats:

 

endtime-starttime

 

 

I want to know in HH:MM:SS how much time inbetween starttime and enddtime.

 

 

 

I know:

 

DateDiff(DateInterval.Second, starttime, endTime)

 

will return the number of seconds, but its the total number of seconds, not the ones leftover from hours and minutes. Please help.

www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
  • *Experts*
Posted

If you use the proper CLR-compliant method (DateTime structure), you can do it something like this:

 

        Dim date1 As DateTime = DateTime.Parse("10:00:00")
       Dim date2 As DateTime = DateTime.Parse("11:00:00")
       Dim diff As TimeSpan = date2.Subtract(date1)

       MessageBox.Show(diff.Hours.ToString())

It should show a one hour different between the two.

 

As always, consult the MSDN for more info.

  • *Experts*
Posted
I think it will be better formatted if you use diff.ToString and it will return a string like you wanted. However, with your, you could get a time like 6:7:2, whereas with diff.ToString it would be 6:07:02.

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...