|
-
Apr 2nd, 2002, 10:43 AM
#1
Thread Starter
New Member
URGENT!!!...calculating time!!!
I'm inputting a time as 8.30a.m., and I want to calculate the difference between the mentioned time with the current time...e.g...12:30 p.m.
How do I code it?...
thanx for the help anyway...
-
Apr 2nd, 2002, 10:45 AM
#2
PowerPoster
Delta=DateDiff("s",StartTime,Now)
replace "s" if you want anything besides seconds
-
Apr 2nd, 2002, 10:47 AM
#3
Bouncy Member
VB Code:
MsgBox DateDiff("s", #8:30:00 AM#, #12:30:00 PM#)
-
Apr 2nd, 2002, 10:48 AM
#4
Thread Starter
New Member
wut's delta...izzit a string or wut?
to darre...the 8.30 a.m. time will be inputted from a combo box...so how do I assigned a variable to it...and also the current time...?
-
Apr 2nd, 2002, 10:50 AM
#5
Bouncy Member
here's function you might find useful
VB Code:
Public Function TimeDiffString(dtmStart, dtmEnd) As String
On Error GoTo ErrorHandler
Dim intHrs, intMins, intSecs As Integer
Dim strHrsString, strMinsString, strSecsString As String
'Calculate the mins and secs
intHrs = DateDiff("h", dtmStart, dtmEnd)
intMins = DateDiff("n", dtmStart, dtmEnd) Mod 60
intSecs = DateDiff("s", dtmStart, dtmEnd) Mod 60
'May need to take 1 off the minutes and the hours
If CInt(Format(dtmEnd, "nn")) < CInt(Format(dtmStart, "nn")) Then intHrs = intHrs - 1
If CInt(Format(dtmEnd, "ss")) < CInt(Format(dtmStart, "ss")) Then intMins = intMins - 1
'Create the strings
If intHrs <= 0 Then
strHrsString = ""
ElseIf intHrs = 1 Then
strHrsString = " 1 hour"
Else
strHrsString = " " & intHrs & " hours"
End If
If intMins <= 0 Then
strMinsString = ""
ElseIf intMins = 1 Then
strMinsString = " 1 minute"
Else
strMinsString = " " & intMins & " minutes"
End If
If intSecs <= 0 Then
strSecsString = ""
ElseIf intSecs = 1 Then
strSecsString = " 1 second"
Else
strSecsString = " " & intSecs & " seconds"
End If
'If all aren't "" then will need an 'and'
If strMinsString <> "" And strSecsString <> "" Then
strMinsString = strMinsString & " and"
If strHrsString <> "" Then strHrsString = strHrsString & ","
ElseIf strHrsString <> "" And (strMinsString <> "" Or strSecsString <> "") Then
strHrsString = strHrsString & " and"
End If
'Result
TimeDiffString = strHrsString & strMinsString & strSecsString
CleanUp:
Exit Function
ErrorHandler:
MsgBox Err.Description, , Err.Number
Resume CleanUp
End Function
-
Apr 2nd, 2002, 10:51 AM
#6
Bouncy Member
Originally posted by w_aun83
wut's delta...izzit a string or wut?
to darre...the 8.30 a.m. time will be inputted from a combo box...so how do I assigned a variable to it...and also the current time...?
it returns a long value
-
Apr 2nd, 2002, 10:53 AM
#7
Thread Starter
New Member
DTPicker problem...
I'm using the drpShrtTime DTPicker...the problem is when it is added to the database...it prints the date also...and after trying to format the time...it still shows the seconds...
-
Apr 2nd, 2002, 10:54 AM
#8
Bouncy Member
using the TimeDiffString function i posted try this
VB Code:
MsgBox TimeDiffString(#8:30:00 AM#, #12:30:00 PM#)
-
Apr 2nd, 2002, 10:58 AM
#9
Bouncy Member
are you saying that you dont want the date saved to the record then???
-
Apr 2nd, 2002, 11:02 AM
#10
Thread Starter
New Member
yes...just the time only...
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
|