PDA

View Full Version : datetime function DateAddMinute



Wim Schimmel
10-Feb-2016, 02:54 PM
Hi,

I will substract some minutes from a datetime (worktime minus lunch)
If my time is 16:15 and subtract 75 minuten, dateaddminute calculate 14:00 and not 15:00

If subtract 74 minutes or if my current time is 16:16 the calculate is correct

I add one codeline //wss

Wim

9760

9761



Function DateAddMinuteWSS Global DateTime dtVar Integer iAdd Returns DateTime
DateTime dtVar2
Integer iCrnt iOverflow
If (IsNullDateTime(dtVar) or not(IsDateValid(dtVar))) Begin
Error DFERR_INVALID_DATETIME
Function_Return dtVar2
End
Move (DateGetMinute(dtVar)) to iCrnt
Move (iCrnt + iAdd) to iAdd
Move (ModAlt(iAdd,60)) to iCrnt
Move (DateSetMinute(dtVar,iCrnt)) to dtVar2
Move (iAdd/60 + If(iAdd<0,-1,0)) to iOverflow

If (iCrnt = 0 and iAdd < 0) Add 1 to iOverflow // wss

If (iOverflow) Begin
Move (DateAddHour(dtVar2,iOverflow)) to dtVar2
End
Function_Return dtVar2
End_Function

John Tuohy
10-Feb-2016, 07:13 PM
Well somebody was out to lunch when they did this. Try this package. You will need to drop this in pkg and precompile.

I did the same thing you did but in, what I hope, is a slightly different way:

from:

Move (iAdd/60 + If(iAdd<0,-1,0)) to iOverflowto:

Move (iAdd/60 + If(iAdd<0 and iCrnt<>0,-1,0)) to iOverflow

It looks like the same issue applies to all of the new date "Add" functions. Let us know if this works and thank you for finding, solving and reporting this.

-John