Operating System - OpenVMS
1820879 Members
5207 Online
109628 Solutions
New Discussion юеВ

Calculating delta time in a CP

 
SOLVED
Go to solution
Alon Jacob
Frequent Advisor

Calculating delta time in a CP

Hello all.

Can you give me an idea on how to calculate a delta time in order to use it in a delete/before command, so it will delete files older than X days?
I can get the current time using f$time() lexical, but what next?
7 REPLIES 7
David B Sneddon
Honored Contributor
Solution

Re: Calculating delta time in a CP

Alon,

How about

$ delete file.type;/created/before=today-7-00:00

to delete files older than 7 days?

Regards
Dave
Bojan Nemec
Honored Contributor

Re: Calculating delta time in a CP

Hi,

To compute the same date you can use the lexical function f$cvtime.


$ date = f$cvtime("today-7-00:00","ABSOLUTE")


Bojan
Alon Jacob
Frequent Advisor

Re: Calculating delta time in a CP

David.

It works like a charm.
Thanks a-lot.


Alon.
Uwe Zessin
Honored Contributor

Re: Calculating delta time in a CP

Oh, by the way:

"today-7-00:00" is not a delta time - it is a 'combination time'.

$ write sys$output f$time()," ",f$cvtime("today-7-00:00","absolute")
20-JUL-2004 10:00:37.85 13-JUL-2004 00:00:00.00

"-7-00:00" is not a delta time, either - it is still a combination time meaning 'now - 7 days'.

$ write sys$output f$time()," ",f$cvtime("-7-00:00","absolute")
20-JUL-2004 10:00:41.08 13-JUL-2004 10:00:41.08
$
.
John Gillings
Honored Contributor

Re: Calculating delta time in a CP

Alon,

As pointed out, a combination time will do what you want.

But for those interested in "true" delta times, DCL is missing the ability to find the difference between two absolute times.

No promises, but I think delta time calculations in DCL have been implemented for an upcoming version.

In the mean time, you can use combination times to calculate the difference between two delta times, T0 and T1, by successive approximation. The idea is to find time D such that T0+D = T1. Unfortunately because of the "key space" of times, a true binary search isn't worth the effort. Instead this algorithm works its way down the fields. Being an iterative, it's not exceptionally fast. Maximum difference is 10,000 days (~27 years).

You could always write a program to do this. I'm not sure if the cost of an image activation is greater than all that looping.
A crucible of informative mistakes
John Gillings
Honored Contributor

Re: Calculating delta time in a CP

same file as before but this time attached as ".TXT" not ".COM" to help Windows

A crucible of informative mistakes
Martin P.J. Zinser
Honored Contributor

Re: Calculating delta time in a CP

Hi,

to quote Guy Peleg from comp.os.vms

In the technical update day in the Netherlands it was mentioned that it
is hard to do delta time calculations.
In VMS V7.3-2 we added new lexical function F$DELTA_TIME. See the
following example:

BLUSKY> a=f$time()
BLUSKY> b=f$time()
BLUSKY> sh sym a
A = " 3-OCT-2003 17:39:58.54"
BLUSKY> sh sym b
B = " 3-OCT-2003 17:40:23.22"
BLUSKY> write sys$output f$delta(a,b)
0 00:00:24.68

hp has it now(TM), John ;-)

Greetings, Martin