date & time difference calculation

Chris Sharman chris.sharman@ccagroup.co.uk
Tue, 18 May 2004 09:09:35 +0100


Lorry Litman wrote:
> Because I'm not familiar with these functions (or the math) in Chris's
> solution
> I have changed the imins define. 

> From:
> def imins int*2 = floor((fdays - idays)*1440 - 24 * ihours)
> To:
> def imins int*2 = floor((((fdays - idays)*24) - ihours)* 60 + .01)

Looks better (I'd incorrectly multiplied hours by 24 rather than 60) - 
well spotted. The 0.01 may help rounding issues, but will also introduce 
the possibility of imins being 60, which is probably undesirable.

Another issue is that floor rounds down, so -4.5 gets rounded to -5.
Not what we want at all.
Easiest fix:
define fdays = absolute(decimaltime(vmsdt1,vmsdt2))
...
define date_diff = ... if (vmsdt1>=vmsdt2) else - ...

Don't know whether that's the problem or not, but the following seems 
to give good results on a couple of test cases.

def fdays = absolute(decimaltime(vmsdt1,vmsdt2))
def idays int*4 = floor(fdays)
def ihours int*2 = floor((fdays - idays)*24)
def imins int*2 = floor(((fdays - idays)*24 - ihours)*60)
def idiff int*9 = idays*10000+ihours*100+imins if (vmsdt1>=vmsdt2) &
	else -(idays*10000+ihours*100+imins)
rep all
go

Chris



-----------------------------------------------------------------------

Any views expressed in this message are those of the sender and not
necessarily those of CCA Group.  The unauthorized use, disclosure,
copying or alteration of this message is forbidden.  The contents of
this message may be confidential and/or privileged, copyright CCA Group
and are intended solely for the use of the individual or entity to whom
they are addressed.  Whilst this message has been scanned, CCA Group
cannot guarantee that it is virus free or compatible with your systems
and accepts no responsibility for any loss or damage arising from its
use. The recipient is advised to run their own anti-virus software. If
you receive this message in error please contact
postmaster@ccagroup.co.uk immediately, destroy any copies and delete it
from your computer systems.