date & time difference calculation
Chris Sharman
chris.sharman@ccagroup.co.uk
Mon, 17 May 2004 15:13:57 +0100
Lorry Litman wrote:
> Hi,
>
> How to do a date/time difference calculation?
>
> VMS 7.2, PH 7.10G, RDB 7.0
> In the RDB database the DATE field is INTEGER and the TIME field is
> SMALLINT.
> In the dictionary (century included), the DATE field is type D, size 8,
> datatype ZU, and the TIME field is type N, size 4, datatype ZU.
>
> A new field is being created, call it DATE_DIFF, I suspect it will be
> INTEGER in RDB and Numeric size 10, ZU in the dictionary.
> The display of the DATE_DIFF field is to be in the format of YY:MM:DD:HH:MM.
>
> Any help/suggestions would be much appreciated.
decimaltime(vmsdatetime1, vmsdatetime2) will return (vmsdatetime1 -
vmsdatetime2) as a signed, floating point, number of days.
You're on your own in deciding how many difference days in a difference
month or year, it being variable. I'd've recommended the VMS delta time
format of dddd-hh:mm (good for just under 30 years).
; convert own-brand date & time into vms date/time format
def vmsdt1 vmsdate = floor(mydate) + floor(mytime*0.01)/24 + &
mod(mytime,100)/1440
; calculate difference
def fdays = decimaltime(vmsdt1,vmsdt2)
def idays int*4 = floor(fdays)
def ihours int*2 = floor((fdays - idays)*24)
def imins int*2 = floor((fdays - idays)*1440 - 24 * ihours)
def date_dif int*10 = idays*10000 + ihours*100 + imins
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.