date & time difference calculation

Lorry Litman LLitman@exchange.hsc.mb.ca
Mon, 17 May 2004 10:29:35 -0500


This is a multi-part message in MIME format.

--=_Part_1cba85cb$2f56$4488$a8c8$56d2fd54b88f
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Thank-you for your reply.

I neglected to mention that I need to store the result in format YYMMDDHH=
MM.
In trying the code below I seem to be getting incorrect results. I'll hav=
e
to play with it a little more as I'm not that familiar with these functio=
ns.

As an example,
 difference between 21-jan-1999-10:15 and 20-jan-1999-14:00 results in 27=
35
(27 hrs, 35 min) when I expected a result of 2015 (20 hrs, 15 min),
 difference between 10:15 and 10:00 comes up as 14 instead of 15.

Thanx Lorry.



-----Original Message-----

This e-mail and/or any documents in this transmission is intended for the=
 address(s) only and may contain legally privileged or confidential infor=
mation. Any unauthorized use, disclosure, distribution, copying or dissem=
ination is strictly prohibited. If you receive this transmission in error=
, please notify the sender immediately and return the original.
--=_Part_1cba85cb$2f56$4488$a8c8$56d2fd54b88f
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit

From: Chris Sharman [mailto:chris.sharman@ccagroup.co.uk]
Sent: Monday, May 17, 2004 9:14 AM
To: Lorry Litman; PowerH List
Subject: Re: date & time difference calculation
MIME-Version: 1.0


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.
--=_Part_1cba85cb$2f56$4488$a8c8$56d2fd54b88f--