i want to add 33 hours 20 min 22 sec in
7 :30:00 How to do this .
any one have sugg??
Printable View
i want to add 33 hours 20 min 22 sec in
7 :30:00 How to do this .
any one have sugg??
youll have to apply the DateAdd function to it 3 times (one for hours, one for minutes, and one for seconds) I think.
VB Code:
newtime = Format(DateAdd("h", 33, DateAdd("n", 20, DateAdd("s", 22, Text1.Text))), "hh:mm:ss ampm")
Something like this:
VB Code:
Private Sub Form_Load() Dim CurTime As String Dim TimeToAdd As String Dim NewTime As String CurTime = Format(Now, "mm/dd/yyyy ") & Format("7:30:00", "hh:nn:ss") TimeToAdd = "33:20:22" NewTime = DateAdd("h", CDbl(Left(TimeToAdd, 2)), CurTime) NewTime = DateAdd("n", CDbl(Mid(TimeToAdd, 4, 2)), NewTime) NewTime = DateAdd("s", CDbl(Right(TimeToAdd, 2)), NewTime) Debug.Print NewTime End Sub
This will add to the time and return the new time...
VB Code:
Private Function TimeAdd(dTime As Date, nHours As Integer, nMinutes As Integer, _ nSeconds As Integer) As Date TimeAdd = FormatDateTime(DateAdd("h", nHours, (DateAdd("n", nMinutes, _ DateAdd("s", nSeconds, dTime)))), vbLongTime) End Function
Usage:
VB Code:
Dim NewTime as Date NewTime = TimeAdd("7:30:00 AM", 33, 20, 22)
Nice :DQuote:
Originally posted by seaweed
This will add to the time and return the new time...
VB Code:
Private Function TimeAdd(dTime As Date, nHours As Integer, nMinutes As Integer, _ nSeconds As Integer) As Date TimeAdd = FormatDateTime(DateAdd("h", nHours, (DateAdd("n", nMinutes, _ DateAdd("s", nSeconds, dTime)))), vbLongTime) End Function
Usage:
VB Code:
Dim NewTime as Date NewTime = TimeAdd("7:30:00 AM", 33, 20, 22)