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...
Printable View
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...
Delta=DateDiff("s",StartTime,Now)
replace "s" if you want anything besides seconds
VB Code:
MsgBox DateDiff("s", #8:30:00 AM#, #12:30:00 PM#)
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...?
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
:D
it returns a long valueQuote:
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...?
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...
using the TimeDiffString function i posted try this
VB Code:
MsgBox TimeDiffString(#8:30:00 AM#, #12:30:00 PM#)
:D
are you saying that you dont want the date saved to the record then???
yes...just the time only...