| | |
how to calculate time duration?
Thread Solved |
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 :
e.g :
Start = 5/24/2008
End = 7/24/2008
Result = 0 Years 2 Months
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)
Private Sub btnCalculate_Click() Dim Temp, thn, bln As Long Temp = DateDiff("m", DTPStart.Value, DTPEnd.Value) thn = Temp \ 12 ' Year bln = Temp Mod 12 ' Month MsgBox thn & " Years " & bln & " Months" End Sub
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jul 2007
Posts: 23
Reputation:
Solved Threads: 0
•
•
•
•
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 :
e.g :Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub btnCalculate_Click() Dim Temp, thn, bln As Long Temp = DateDiff("m", DTPStart.Value, DTPEnd.Value) thn = Temp \ 12 ' Year bln = Temp Mod 12 ' Month MsgBox thn & " Years " & bln & " Months" End Sub
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
vb Syntax (Toggle Plain Text)
Private Function TimeDiff(Time1 As String, Time2 As String) As String Dim MinsDiff As String Dim TheHours As String MinsDiff = DateDiff("n", Time1, Time2) 'If midnight is between times MinsDiff = IIf(MinsDiff < 0, MinsDiff + 1440, MinsDiff) TheHours = Format(Int(MinsDiff / 60), "00") MinsDiff = Format(MinsDiff Mod 60, "00") TimeDiff = TheHours & ":" & MinsDiff End Function Private Sub Command1_Click() Dim x As String x = TimeDiff(DTPicker1.Value, DTPicker2.Value) MsgBox x End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- How to calculate and compare DateTime with Integer(c#) (ASP.NET)
- i need help plz!!!!!!!!!! (C++)
- increment time with for looping (PHP)
- help help plzzzzzzzz (Java)
- Modular Arithmetic (Computer Science)
- time.h help (C++)
- Waiting Room Access DB (Visual Basic 4 / 5 / 6)
- how to minus the time (VB.NET)
- validation of some kind (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to group the data in datareport
- Next Thread: Recordset problem
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






