how to calculate time duration?

Thread Solved

Join Date: Jul 2007
Posts: 23
Reputation: elanch is an unknown quantity at this point 
Solved Threads: 0
elanch elanch is offline Offline
Newbie Poster

how to calculate time duration?

 
0
  #1
May 24th, 2008
hi all!
I have created two datetime picker for getting input for start time and end time.
but i could'nt able to calculate time duration between them.

How to calculate the time duration by getting start and end time input.

Thanks in advance
elanch
Defeat the defeat before the defeat defeats you
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: how to calculate time duration?

 
0
  #2
May 24th, 2008
U can compare dates in terms of days , months or years as u wish by DateDiff Function in VB6.
As DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
Where interval will be in string as :
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
It will return difference of two dates as long according to parameters provided.

following codes is an example :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btnCalculate_Click()
  2. Dim Temp, thn, bln As Long
  3. Temp = DateDiff("m", DTPStart.Value, DTPEnd.Value)
  4. thn = Temp \ 12 ' Year
  5. bln = Temp Mod 12 ' Month
  6. MsgBox thn & " Years " & bln & " Months"
  7. End Sub
e.g :
Start = 5/24/2008
End = 7/24/2008
Result = 0 Years 2 Months
Last edited by Jx_Man; May 24th, 2008 at 6:29 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: elanch is an unknown quantity at this point 
Solved Threads: 0
elanch elanch is offline Offline
Newbie Poster

Re: how to calculate time duration?

 
0
  #3
May 24th, 2008
Originally Posted by Jx_Man View Post
U can compare dates in terms of days , months or years as u wish by DateDiff Function in VB6.
As DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
Where interval will be in string as :
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
It will return difference of two dates as long according to parameters provided.

following codes is an example :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btnCalculate_Click()
  2. Dim Temp, thn, bln As Long
  3. Temp = DateDiff("m", DTPStart.Value, DTPEnd.Value)
  4. thn = Temp \ 12 ' Year
  5. bln = Temp Mod 12 ' Month
  6. MsgBox thn & " Years " & bln & " Months"
  7. End Sub
e.g :
Start = 5/24/2008
End = 7/24/2008
Result = 0 Years 2 Months



Thank u 4 replying
sory i could not understand

i just need to calculate time duration not the diff. between dates.

Getting input

Start time: 05:40
End time: 06:40

output to be calculated

Time duration = 01:10

kindly help.
Defeat the defeat before the defeat defeats you
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: how to calculate time duration?

 
2
  #4
May 24th, 2008
  1. Private Function TimeDiff(Time1 As String, Time2 As String) As String
  2. Dim MinsDiff As String
  3. Dim TheHours As String
  4. MinsDiff = DateDiff("n", Time1, Time2)
  5. 'If midnight is between times
  6. MinsDiff = IIf(MinsDiff < 0, MinsDiff + 1440, MinsDiff)
  7. TheHours = Format(Int(MinsDiff / 60), "00")
  8. MinsDiff = Format(MinsDiff Mod 60, "00")
  9. TimeDiff = TheHours & ":" & MinsDiff
  10. End Function
  11.  
  12.  
  13. Private Sub Command1_Click()
  14. Dim x As String
  15. x = TimeDiff(DTPicker1.Value, DTPicker2.Value)
  16. MsgBox x
  17. End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: elanch is an unknown quantity at this point 
Solved Threads: 0
elanch elanch is offline Offline
Newbie Poster

Re: how to calculate time duration?

 
0
  #5
May 26th, 2008
thank u.
problem 4 me is solved.

In date time picker AM/PM option is there but 24 Hrs format is not there. Is there any option to change the format.(I have used custom format)
Defeat the defeat before the defeat defeats you
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC