Results 1 to 10 of 10

Thread: URGENT!!!...calculating time!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    8

    Question 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...

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Delta=DateDiff("s",StartTime,Now)

    replace "s" if you want anything besides seconds

  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    VB Code:
    1. MsgBox DateDiff("s", #8:30:00 AM#, #12:30:00 PM#)
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    8
    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...?

  5. #5
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    here's function you might find useful

    VB Code:
    1. Public Function TimeDiffString(dtmStart, dtmEnd) As String
    2. On Error GoTo ErrorHandler
    3.  
    4.     Dim intHrs, intMins, intSecs As Integer
    5.     Dim strHrsString, strMinsString, strSecsString As String
    6.  
    7.         'Calculate the mins and secs
    8.         intHrs = DateDiff("h", dtmStart, dtmEnd)
    9.         intMins = DateDiff("n", dtmStart, dtmEnd) Mod 60
    10.         intSecs = DateDiff("s", dtmStart, dtmEnd) Mod 60
    11.        
    12.         'May need to take 1 off the minutes and the hours
    13.         If CInt(Format(dtmEnd, "nn")) < CInt(Format(dtmStart, "nn")) Then intHrs = intHrs - 1
    14.         If CInt(Format(dtmEnd, "ss")) < CInt(Format(dtmStart, "ss")) Then intMins = intMins - 1
    15.        
    16.         'Create the strings
    17.         If intHrs <= 0 Then
    18.             strHrsString = ""
    19.         ElseIf intHrs = 1 Then
    20.             strHrsString = " 1 hour"
    21.         Else
    22.             strHrsString = " " & intHrs & " hours"
    23.         End If
    24.         If intMins <= 0 Then
    25.             strMinsString = ""
    26.         ElseIf intMins = 1 Then
    27.             strMinsString = " 1 minute"
    28.         Else
    29.             strMinsString = " " & intMins & " minutes"
    30.         End If
    31.         If intSecs <= 0 Then
    32.             strSecsString = ""
    33.         ElseIf intSecs = 1 Then
    34.             strSecsString = " 1 second"
    35.         Else
    36.             strSecsString = " " & intSecs & " seconds"
    37.         End If
    38.        
    39.         'If all aren't "" then will need an 'and'
    40.         If strMinsString <> "" And strSecsString <> "" Then
    41.             strMinsString = strMinsString & " and"
    42.             If strHrsString <> "" Then strHrsString = strHrsString & ","
    43.         ElseIf strHrsString <> "" And (strMinsString <> "" Or strSecsString <> "") Then
    44.             strHrsString = strHrsString & " and"
    45.         End If
    46.        
    47.         'Result
    48.         TimeDiffString = strHrsString & strMinsString & strSecsString
    49.  
    50. CleanUp:
    51.     Exit Function
    52.    
    53. ErrorHandler:
    54.     MsgBox Err.Description, , Err.Number
    55.     Resume CleanUp
    56. End Function

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  6. #6
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    8

    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...

  8. #8
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    using the TimeDiffString function i posted try this

    VB Code:
    1. MsgBox TimeDiffString(#8:30:00 AM#, #12:30:00 PM#)

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  9. #9
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    are you saying that you dont want the date saved to the record then???
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Posts
    8
    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
  •  



Click Here to Expand Forum to Full Width