Results 1 to 6 of 6

Thread: time function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2002
    Posts
    27

    time function

    i want to add 33 hours 20 min 22 sec in
    7 :30:00 How to do this .
    any one have sugg??

  2. #2
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    youll have to apply the DateAdd function to it 3 times (one for hours, one for minutes, and one for seconds) I think.

  3. #3
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    VB Code:
    1. newtime = Format(DateAdd("h", 33, DateAdd("n", 20, DateAdd("s", 22, Text1.Text))), "hh:mm:ss ampm")

  4. #4
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Something like this:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim CurTime As String
    3. Dim TimeToAdd As String
    4. Dim NewTime As String
    5.  
    6.     CurTime = Format(Now, "mm/dd/yyyy ") & Format("7:30:00", "hh:nn:ss")
    7.     TimeToAdd = "33:20:22"
    8.     NewTime = DateAdd("h", CDbl(Left(TimeToAdd, 2)), CurTime)
    9.     NewTime = DateAdd("n", CDbl(Mid(TimeToAdd, 4, 2)), NewTime)
    10.     NewTime = DateAdd("s", CDbl(Right(TimeToAdd, 2)), NewTime)
    11.     Debug.Print NewTime
    12.  
    13. End Sub
    McGenius

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    If you just want the time returned (no date) then...

    This will add to the time and return the new time...
    VB Code:
    1. Private Function TimeAdd(dTime As Date, nHours As Integer, nMinutes As Integer, _
    2.                            nSeconds As Integer) As Date
    3.                            
    4.     TimeAdd = FormatDateTime(DateAdd("h", nHours, (DateAdd("n", nMinutes, _
    5.                                DateAdd("s", nSeconds, dTime)))), vbLongTime)
    6.                                
    7. End Function

    Usage:
    VB Code:
    1. Dim NewTime as Date
    2.  
    3. NewTime = TimeAdd("7:30:00 AM", 33, 20, 22)
    ~seaweed

  6. #6
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: If you just want the time returned (no date) then...

    Originally posted by seaweed
    This will add to the time and return the new time...
    VB Code:
    1. Private Function TimeAdd(dTime As Date, nHours As Integer, nMinutes As Integer, _
    2.                            nSeconds As Integer) As Date
    3.                            
    4.     TimeAdd = FormatDateTime(DateAdd("h", nHours, (DateAdd("n", nMinutes, _
    5.                                DateAdd("s", nSeconds, dTime)))), vbLongTime)
    6.                                
    7. End Function

    Usage:
    VB Code:
    1. Dim NewTime as Date
    2.  
    3. NewTime = TimeAdd("7:30:00 AM", 33, 20, 22)
    Nice

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