date & time difference calculation
Lorry Litman
LLitman@exchange.hsc.mb.ca
Mon, 17 May 2004 14:17:29 -0500
This is a multi-part message in MIME format.
--=_Part_d3723948$e328$48d3$9290$9815ffe094c2
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Hi Joe,
The email attachment got lost in the replies.
Here's the info. At the end is the problem I'm still trying to work out.
> Lorry Litman wrote:
>
> Hi,
>=20
> How to do a date/time difference calculation?
>=20
> 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.
>=20
> 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.
> I need to store the DATE_DIFF result in format YYMMDDHHMM.
> The display of the DATE_DIFF field on the screen is to be in the format=
of
YY:MM:DD:HH:MM.
>=20
> Any help/suggestions would be much appreciated.
> Chris replied
>
> decimaltime(vmsdatetime1, vmsdatetime2) will return (vmsdatetime1 -=20
> vmsdatetime2) as a signed, floating point, number of days.
>=20
> You're on your own in deciding how many difference days in a difference=
=20
> month or year, it being variable. I'd've recommended the VMS delta time=
=20
> format of dddd-hh:mm (good for just under 30 years).
>=20
> ; convert own-brand date & time into vms date/time format
> def vmsdt1 vmsdate =3D floor(mydate) + floor(mytime*0.01)/24 + &
> mod(mytime,100)/1440
> ; calculate difference
> def fdays =3D decimaltime(vmsdt1,vmsdt2)
> def idays int*4 =3D floor(fdays)
> def ihours int*2 =3D floor((fdays - idays)*24)
> def imins int*2 =3D floor((fdays - idays)*1440 - 24 * ihours)
> def date_dif int*10 =3D idays*10000 + ihours*100 + imins
I tried Chris' suggestion which was very helpful (thank-you Chris).
I ran into a problem with the hour & minute calculation.
As an example,=20
difference between 21-jan-1999-10:15 and 20-jan-1999-14:00
resulted in 2735 (27 hrs, 35 min)
I expected a result of 2015 (20 hrs, 15 min),=20
=20
difference between 10:15 and 10:00 comes up as 14 instead of 15.=20
Because I'm not familiar with these functions (or the math) in Chris's
solution
I have changed the imins define.=20
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_d3723948$e328$48d3$9290$9815ffe094c2
Content-Type: message/rfc822
Content-Transfer-Encoding: 8bit
from: def imins int*2 = floor((fdays - idays)*1440 - 24 * ihours)
to: def imins int*2 = floor((((fdays - idays)*24) - ihours)* 60 + .01)
MIME-Version: 1.0
I believe this now gives me the correct result in days,hours,minutes.
However, I need the result in years,months,days,hours,minutes.
As an example
difference between 30-dec-2004-10:06 and 11-oct-2003-10:30
results in 4452336 (445 days, 23 hours, 36 minutes)
I need the result as 0102192336 (1 year, 2 months, 19 days, 23 hours, 36
minutes)
Any suggestions?
Maybe there are different powerhouse functions I can/should use.
Thanx
Lorry
--=_Part_d3723948$e328$48d3$9290$9815ffe094c2--