|
-
Aug 20th, 2000, 02:44 AM
#1
Thread Starter
Addicted Member
hi there ,
i have a table that include the next fields :
1. EventID
2. StartTime
3. EndTime
i want to sum (EndTime-StartTime) but there is a problem !!!
4 eg. if i m adding 12:00 to 11:00 i get 23:00 , so far so good ! BUT if i m adding 12:00 to 13:00 i get 1:00 Not so good !!!
my question is how to add time and recive the correct sum value ?
tnx lirlir
The MORE I get to know,
I realize that I know NOTHING !
-
Aug 20th, 2000, 03:01 AM
#2
So Unbanned
This is a bit crude but it works:
Code:
Dim MyH, MyM As Integer
Dim MyTime, MyTime2 As String
MyTime = Format("1:23", "hh:mm")
MyTime2 = Format("3:41", "hh:mm")
MyH = Val(Left$(MyTime, 2)) + Val(Left$(MyTime2, 2))
MyM = Val(Right$(MyTime, 2)) + Val(Right$(MyTime2, 2))
If MyH > 12 Then MyH = MyH - 12
If MyM > 60 Then MyH = MyH + 1: MyM = MyM - 60
MsgBox = Format(MyH & ":" & MyM, "hh:mm")
Hope it works for you,
-
Aug 20th, 2000, 03:09 AM
#3
Thread Starter
Addicted Member
not so good
i tried that code
Private Sub Form_Activate()
Dim MyH, MyM As Integer
Dim MyTime, MyTime2 As String
MyTime = Format("23:23", "hh:mm")
MyTime2 = Format("3:41", "hh:mm")
MyH = Val(Left$(MyTime, 2)) + Val(Left$(MyTime2, 2))
MyM = Val(Right$(MyTime, 2)) + Val(Right$(MyTime2, 2))
If MyH > 12 Then MyH = MyH - 12
If MyM > 60 Then MyH = MyH + 1: MyM = MyM - 60
Call MsgBox(Format(MyH & ":" & MyM, "hh:mm"))
End Sub
and got this result : 15:04
The MORE I get to know,
I realize that I know NOTHING !
-
Aug 20th, 2000, 09:43 AM
#4
Declare it as Date.
Code:
Function AddDate(Time1 As Date, Time2 As Date) As Date
AddDate = CDate(Time1 + Time2)
End Function
Private Sub Command1_Click()
Print AddDate("1:59", "1:02")
End Sub
-
Aug 20th, 2000, 10:14 AM
#5
Member
check out the dateadd function
-
Aug 21st, 2000, 01:07 AM
#6
Thread Starter
Addicted Member
What r u talking about d.paulson, what function.
pls write the syntax if u can.
tnx lirlir
The MORE I get to know,
I realize that I know NOTHING !
-
Aug 21st, 2000, 01:34 AM
#7
Hyperactive Member
Code:
Public Function DisplayTimeSum(Time1 as Time, Time2 as Time) as String
Dim sglResult as Single
sglResult = CSng(Time1 + Time2) * 24
DisplayTimeSum = format(Int(sglResult),"00:") & format((sglResult - int(sglResult)) * 60,"00")
End Function
Msgbox DisplayTimeSume(TimeValue("23:23"),TimeValue("3:41"))
You will find the answer is 27:04
-
Aug 21st, 2000, 01:42 AM
#8
Thread Starter
Addicted Member
hey tnx,
it's look fulfilling ,but its raise an error as if the
"time" if User-defined type is undefined.
what is the reference to the "time".
tnx lirlir
The MORE I get to know,
I realize that I know NOTHING !
-
Aug 21st, 2000, 01:52 AM
#9
Hyperactive Member
Ah sorry... replace "Time" with "Date" as a datatype and it should work perfectly.
You might want to add some checking or change the datatypes ot strings and then perform a "TimeValue" on them but the choice is yours.
-
Aug 21st, 2000, 01:57 AM
#10
Thread Starter
Addicted Member
Yes Sir,
u r the B-52 of all programmers.
very helpfull indeed !!!
tnx mate
lirlir
The MORE I get to know,
I realize that I know NOTHING !
-
Aug 21st, 2000, 09:13 AM
#11
Member
Returns a Variant (Date) containing a date to which a specified time interval has been added.
Syntax
DateAdd(interval, number, date)
The DateAdd function syntax has thesenamed arguments:
Part Description
interval Required.String expression that is the interval of time you want to add.
number Required.Numeric expression that is the number of intervals you want to add. It can be positive (to get dates in the future) or negative (to get dates in the past).
date Required. Variant (Date) or literal representing date to which the interval is added.
Settings
The intervalargument has these settings:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
Remarks
You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now.
To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").
The DateAdd function won't return an invalid date. The following example adds one month to January 31:
DateAdd("m", 1, "31-Jan-95")
In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.
If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error occurs.
If number isn't aLong value, it is rounded to the nearest whole number before being evaluated.
Note The format of the return value for DateAdd is determined by Control Panel settings, not by the format that is passed in date argument.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|