Adding minutes to time

  • Thread starter Thread starter paul
  • Start date Start date
P

paul

How do I create a time variable and increment the
minutes. My attempt is incrementing the date instead of
the time. How could i get it to output: 11:00 11:20 etc?

Function Test()
Dim dteStartTime As Date
Dim dteEndTime As Date
Dim intMinIncrement As Integer
Dim dteNewTime As Date

dteStartTime = #11:00:00 AM#
dteEndTime = #3:00:00 PM#
intMinIncement = 20

dteNewTime = dteStartTime

Do Until dteStartTime > dteEndTime
dteNewTime = dteNewTime + intMinIncement
Debug.Print dteNewTime
Loop
End Function
 
Could you suggest a method of converting seconds to hh:mm:ss format? ie 418
seconds = 0:06:58.

I obtained the seconds with: CLng(DateDiff("s", [TimeOn], [TimeOff]))
Thanks
 
I did it!
\60 and Mod 60 .

Sid said:
Could you suggest a method of converting seconds to hh:mm:ss format? ie 418
seconds = 0:06:58.

I obtained the seconds with: CLng(DateDiff("s", [TimeOn], [TimeOff]))
Thanks

Allen Browne said:
Use DateAdd(), with "n" for minutes.
("m" is for months).
 
Could be done with Mod and integer division (\).

Doug Steele has a function that may do this for you:
http://members.rogers.com/douglas.j.steele/Diff2Dates.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sid said:
Could you suggest a method of converting seconds to hh:mm:ss format? ie 418
seconds = 0:06:58.

I obtained the seconds with: CLng(DateDiff("s", [TimeOn], [TimeOff]))
Thanks

Allen Browne said:
Use DateAdd(), with "n" for minutes.
("m" is for months).
 
Isn't: DateDiff("s", Date1, Date2) AS SecondsValue
a reliable method of deriving total seconds between two times?
(general dates, 02/23/2003 2:34:00 PM) Works well in many tests so far.
Thanks
Allen Browne said:
Could be done with Mod and integer division (\).

Doug Steele has a function that may do this for you:
http://members.rogers.com/douglas.j.steele/Diff2Dates.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sid said:
Could you suggest a method of converting seconds to hh:mm:ss format? ie 418
seconds = 0:06:58.

I obtained the seconds with: CLng(DateDiff("s", [TimeOn], [TimeOff]))
Thanks

Allen Browne said:
Use DateAdd(), with "n" for minutes.
("m" is for months).

How do I create a time variable and increment the
minutes. My attempt is incrementing the date instead of
the time. How could i get it to output: 11:00 11:20 etc?

Function Test()
Dim dteStartTime As Date
Dim dteEndTime As Date
Dim intMinIncrement As Integer
Dim dteNewTime As Date

dteStartTime = #11:00:00 AM#
dteEndTime = #3:00:00 PM#
intMinIncement = 20

dteNewTime = dteStartTime

Do Until dteStartTime > dteEndTime
dteNewTime = dteNewTime + intMinIncement
Debug.Print dteNewTime
Loop
End Function
 
Thanks, I'll try it.
I seem to recall that DateDiff didn't do all that was suggested for me.
Sid said:
Isn't: DateDiff("s", Date1, Date2) AS SecondsValue
a reliable method of deriving total seconds between two times?
(general dates, 02/23/2003 2:34:00 PM) Works well in many tests so far.
Thanks
Allen Browne said:
Could be done with Mod and integer division (\).

Doug Steele has a function that may do this for you:
http://members.rogers.com/douglas.j.steele/Diff2Dates.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sid said:
Could you suggest a method of converting seconds to hh:mm:ss format?
ie
418
seconds = 0:06:58.

I obtained the seconds with: CLng(DateDiff("s", [TimeOn], [TimeOff]))
Thanks

Use DateAdd(), with "n" for minutes.
("m" is for months).

How do I create a time variable and increment the
minutes. My attempt is incrementing the date instead of
the time. How could i get it to output: 11:00 11:20 etc?

Function Test()
Dim dteStartTime As Date
Dim dteEndTime As Date
Dim intMinIncrement As Integer
Dim dteNewTime As Date

dteStartTime = #11:00:00 AM#
dteEndTime = #3:00:00 PM#
intMinIncement = 20

dteNewTime = dteStartTime

Do Until dteStartTime > dteEndTime
dteNewTime = dteNewTime + intMinIncement
Debug.Print dteNewTime
Loop
End Function
 
Back
Top