PDA

View Full Version : Subtracting minutes from a date



jumpjack
08-22-2006, 09:46 AM
I am using a Visual Basic freeware clone (RapidQ), which does not implement DateDiff and DateAdd; where could I find a sample source to subtract MINUTES to a date?
I need to perform calculations like this:
2006/08/21 00:01:00 MINUS 3 minutes = 2006/08/20 23:58:00
Taking into account day or month change due to midnight is quite complex.... I guess I need some kind of timeserial.bas file... if it exists anywhere...

mdmackillop
08-22-2006, 11:41 AM
I'm guessing that your Date/Time is still stored as a number, so you need to subtract 3/1440 (24x60).

jumpjack
08-22-2006, 12:21 PM
I'm guessing that your Date/Time is still stored as a number, so you need to subtract 3/1440 (24x60).
Thanks, but I found that it's much easier if I convert date to separate numbers, rather than doing complex math calcs to convert date to minutes, substract minutes and converting them back to the correct date:


if min-PREALARM<0 then
min = 60-PREALARM
if hour=0 then
hour = 23
if day = 1 then
if month>1 then
month = month - 1
day=MonthDays(month)
else
month = 12
day = MonthDays(12)
year = year - 1
end if
else
day = day-1
end if
else
hour = hour -1
end if
else
min = min-PREALARM
end if

mdmackillop
08-22-2006, 12:37 PM
I'm not sure where the complexity comes in

Sub ShowTimes()
Dim tim1 As Date, tim2 As Date

tim1 = Now()
tim2 = tim1 - 3 / 1440

MsgBox Format(tim1, "dd/mm/yy hh:mm:ss") & vbCr _
& "less three minutes" & vbCr _
& Format(tim2, "dd/mm/yy hh:mm:ss")
End Sub

jumpjack
08-22-2006, 12:43 PM
I'm NOT using VisualBasic, remember? Don't even know if Format() function exists in RapidQ!

mdmackillop
08-22-2006, 12:48 PM
The Format is just for an excel demo of how you subtract a simple fraction from one time to get an earlier time. Have you tried doing this?