Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2009, 08:31 PM
Registered User
 
Join Date: Feb 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Time

My goal is to obtain two times from a user and calculate the difference between those two.

The format I want to use is: 00:00.00 => 01:48.4 (1 minute and 48.4 seconds.)

What is the code for this simple calculation and what are the variable declarations?

Thanks to any who can help me.

I submitted this in the beginners section but appears to be dead in there
 
Old February 16th, 2009, 12:54 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

http://msdn.microsoft.com/en-us/libr....datetime.aspx
http://msdn.microsoft.com/en-us/libr....timespan.aspx
http://msdn.microsoft.com/en-us/libr....tostring.aspx

Code:
Dim t1 As DateTime = CDate( someTextBox.Text ) ' can also use DateTime.Parse...
Dim t2 As DateTime = CDate( anotherTextBox.Text ) ' but why not use what VB gives you?
Dim span As TimeSpan = t2.Subtract( t1 )

Dim duration As String = span.Days.ToString("00") & "." & _
                         span.Hours.ToString("00") & ":" & _              
                         span.Minutes.ToString("00") & ":" & _              
                         span.Seconds.ToString("00") & "." & _
                         (span.Milliseconds/100).ToString("0")
When in doubt, check with MSDN.

N.B.: If didn't want those tenths of a second, we could do it simpler with all-VB built-in functions.





Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing pocket pc time with desktop time bobbyrayudu83 C# 1 April 2nd, 2011 04:28 AM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 01:56 PM
time zone & day light time rajn ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2007 05:02 PM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM
recordcount some time return -2 or sum time -1 pradeep1976 BOOK: Beginning ASP 3.0 1 April 7th, 2005 08:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.