Drstein99 Posted October 14, 2003 Posted October 14, 2003 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. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Volte Posted October 14, 2003 *Experts* Posted October 14, 2003 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. Quote
Drstein99 Posted October 14, 2003 Author Posted October 14, 2003 Ok that wasn't the exact thing I was looking for but it pointed me right and I now have the answer. Thanks for your help case closed. messagebox.show(diff.Hours.ToString & ":" & diff.Minutes.ToString & ":" & diff.Seconds.ToString) Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Volte Posted October 14, 2003 *Experts* Posted October 14, 2003 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. Quote
Drstein99 Posted October 14, 2003 Author Posted October 14, 2003 Perfect! I'm going to be doing alot of time tracking etc... And I'm gonna need this function all over the place. Thank you very much. I'm starting to respect .net better every day because of this forum. With the standard help that is offered with the package I get so lost! Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.