Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get difference between 2 vms time-stamps in DCL

838 views
Skip to first unread message

s...@mail.adldata.com

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
I need, in DCL, to subtract current datetime from a files
created datetime to detemine how long the file has been
around. I don't see any lexicals or other functions for it.

Using DCL, i can parse the date time stamp, calculate individual
differences and put it together to get the age of the file
but i was hoping for something simpler.

sol


Sent via Deja.com http://www.deja.com/
Before you buy.

Hoff Hoffman

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to

In article <893n5h$udv$1...@nnrp1.deja.com>, s...@mail.adldata.com writes:
:I need, in DCL, to subtract current datetime from a files

:created datetime to detemine how long the file has been
:around.
:Using DCL, i can parse the date time stamp, calculate individual

:differences and put it together to get the age of the file
:but i was hoping for something simpler.

Please back up a step -- it is certainly possible to churn out DCL
date calculations, but please first describe why you want this and
what you are up to... It might be easier to use DIRECTORY/BEFORE=delta
or DIRECTORY/SINCE=combination, or some other similar approach...

(Don't dig yourself deeper when another approach might be available.)

As another approach -- one which also does not directly involve date
math -- the following technique can be used to get dates that you can
use for a string-based comparison:

$ threshold = f$cvtime(f$cvtime("TODAY-90-", "absolute"),"COMPARISON")
$ filecdt = f$cvtime(f$file("SYS$LOGIN:LOGIN.COM","CDT"),"COMPARISON")
$ if threshold .gts. filecdt then...

There's a book on DCL available, too... :-)

--------------------------- pure personal opinion ---------------------------
Hoff (Stephen) Hoffman OpenVMS Engineering hoffman#xdelta.zko.dec.com


s...@mail.adldata.com

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
a DCL batch file resubmits itself periodically checking for the
presence of a file in a directory. If a file is there, it
remembers the filename and resubmits itself to check for that
same file later, sending an email to a user about the file
and how long the file has been around.

I kept a counter for the number of times the batch was run
with the file present to decide when an email should be sent.

If the batch runs every 15 minutes, mail is sent to person A each
time it is there. After 4 times, mail is also sent to person B.
after 8 times, person C. After ten times it gives up sending mail
until the file disappears and another file shows up persistently.

I was hoping to make availability the length of time the file
was there instead of just its CDT info.

sol gongola

In article <893vd8$9si$1...@mailint03.im.hou.compaq.com>,

Dave Greenwood

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
s...@mail.adldata.com wrote:
> a DCL batch file resubmits itself periodically checking for the
> presence of a file in a directory. If a file is there, it
> remembers the filename and resubmits itself to check for that
> same file later, sending an email to a user about the file
> and how long the file has been around.
>
> I kept a counter for the number of times the batch was run
> with the file present to decide when an email should be sent.
>
> If the batch runs every 15 minutes, mail is sent to person A each
> time it is there. After 4 times, mail is also sent to person B.
> after 8 times, person C. After ten times it gives up sending mail
> until the file disappears and another file shows up persistently.
>
> I was hoping to make availability the length of time the file
> was there instead of just its CDT info.

We did a similar thing years ago. Basically we keep the counter in a
file and read it each time the job runs. Rather brute force but it
still works.

That said, I picked up a Fortran/Macro program called TIME years ago
that allows you to do time arithmetic. It ought to be hanging around
on the net somewhere. Or I can send you a 15 part VMS_SHARE version,
complete with VAX and alpha .exes.

Dave
--------------
Dave Greenwood Email: Green...@ORNL.GOV
Oak Ridge National Lab %STD-W-DISCLAIMER, I only speak for myself

Scott Vieth

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
Fire up DSNlink and search in the OpenVMS database.
There is an article that contains DCL code that can be
used to calc the difference between two times.

-Scott

s...@mail.adldata.com wrote:

> I need, in DCL, to subtract current datetime from a files

> created datetime to detemine how long the file has been
> around. I don't see any lexicals or other functions for it.
>

> Using DCL, i can parse the date time stamp, calculate individual
> differences and put it together to get the age of the file
> but i was hoping for something simpler.
>

> sol

Carl Perkins

unread,
Feb 24, 2000, 3:00:00 AM2/24/00
to
s...@mail.adldata.com writes...

}a DCL batch file resubmits itself periodically checking for the
}presence of a file in a directory. If a file is there, it
}remembers the filename and resubmits itself to check for that
}same file later, sending an email to a user about the file
}and how long the file has been around.
}
}I kept a counter for the number of times the batch was run
}with the file present to decide when an email should be sent.
}
}If the batch runs every 15 minutes, mail is sent to person A each
}time it is there. After 4 times, mail is also sent to person B.
}after 8 times, person C. After ten times it gives up sending mail
}until the file disappears and another file shows up persistently.
}
}I was hoping to make availability the length of time the file
}was there instead of just its CDT info.
}
}sol gongola

Since you are only talking a matter of 165 minutes or so for the exact
age under normal circumstances, you can do it something like this:

$!
$! you need to have the "filename" symbol defined before this point
$!
$ create_dt = F$File_Atributes(filename,"CDT")
$ create_time = F$CVTime(create_dt,"ABSOLUTE","TIME")
$ create_day = F$CVTime(create_dt,"ABSOLUTE","DAY")
$ now = F$CVTime("","ABSOLUTE","DATETIME")
$ current_day = f$CVTime(now,"ABSOLUTE","DAY")
$ If current_day .EQS. create_day
$ Then
$ file_age = F$CVTIME("''now'-0-''create_time'","ABSOLUTE","TIME")
$ Else
$ If (F$Integer(current_day) - F$Integer(create_day) .GT. 1) .OR. -
(F$CVTime("''now'-0-''create_time'","ABSOLUTE","DAY") .NES. create_day)
$ Then
$ file_age = "more than 24 hours"
$ Else
$ tmp1 = F$CVTime("''now'-0-''create_time'","ABSOLUTE","TIME")
$ tmp2 = F$CVTime("''create_dt'-0-''create_time'","ABSOLUTE","TIME")
$ file_age = F$CVTime("''tmp1'-0-''tmp2'","ABSOLUTE","TIME")
$ EndIf
$ EndIf

This will give you a file_age symbol that is either the text string
"more than 24 hours" if the file is more than 24 hours old, or the
age of the file in hh:mm:ss.hh format if it is less than 24 hours old.

Note that there is one problem with this routine: if the file is open
then the F$File_Atributes(filename,"CDT") part will return an
%SYSTEM-W-ACCONFLICT, file access conflict
followed by various other errors caused by this. (I don't know why it
has this problem - it could have been made in such a way that it didn't.)

If you need to get this for files that are open, you have to do something
more complicated, like a DIR/NOHEAD/NOTRAIL/OUTPUT=FOO.TMP 'filename'
and then parse the output to get the date part.

--- Carl

Bob Kaplow

unread,
Feb 25, 2000, 3:00:00 AM2/25/00
to
In article <893n5h$udv$1...@nnrp1.deja.com>, s...@mail.adldata.com writes:
> I need, in DCL, to subtract current datetime from a files
> created datetime to detemine how long the file has been
> around. I don't see any lexicals or other functions for it.
>
> Using DCL, i can parse the date time stamp, calculate individual
> differences and put it together to get the age of the file
> but i was hoping for something simpler.

If you have DSNlink, search there for an article that includes a procedure
for doing just this.

Bob Kaplow

SPAM: spamr...@ChooseYourmail.com u...@ftc.gov postm...@127.0.0.1

Dale A. Dellutri

unread,
Feb 25, 2000, 3:00:00 AM2/25/00
to
On Thu, 24 Feb 2000 16:44:34 GMT, s...@mail.adldata.com wrote:
> I need, in DCL, to subtract current datetime from a files
> created datetime to detemine how long the file has been
> around. I don't see any lexicals or other functions for it.

> Using DCL, i can parse the date time stamp, calculate individual
> differences and put it together to get the age of the file
> but i was hoping for something simpler.

I don't think there's anything simpler. But the following does what
you want for differences up to 68 years. You could easily modify this
to give the difference in minutes, and then it would work for
differences up to 4080 years.

$!-----------
$! TIMEDIFF.COM - Find the difference in seconds between two VMS
$! comparison times (format: YYYY-MM-DD HH:MM:SS.CC).
$! Computes DS = P2 - P1 (positive if P1 is earlier than P2).
$! Dale Dellutri - 2000-02-25
$! NOTE: This com file will give incorrect results if the difference
$! between the first and second time is greater than 68 years!
$! The calculation of the modified Julian day number is adapted from
$! the Calendar FAQ by Claus Tonderling at:
$! http://www.tondering.dk/claus/calendar.html
$!
$! cvcdtjs - ConVert Comparison Date and Time to modified Julian day number
$! and Seconds since midnight
$cvcdtjs: subroutine
$ year = f$integer(f$extract(0,4,p1))
$ month = f$integer(f$extract(5,2,p1))
$ day = f$integer(f$extract(8,2,p1))
$ a = (14-month)/12
$ y = year+4800-a
$ m = month + 12*a - 3
$ mjdn == day + (153*m+2)/5 + y*365 + y/4 - y/100 + y/400 - 2432046
$ ssm == f$integer(f$extract(6,2,p2)) + -
60*(f$integer(f$extract(3,2,p2)) + 60*f$integer(f$extract(0,2,p2)))
$ exit
$ endsubroutine
$!
$ if p1 .eqs. "" .or. p1 .eqs. "?" .or. p2 .eqs. ""
$ then
$ write sys$output "TIMEDIFF.COM - Difference in seconds = P2 - P1."
$ write sys$output " P1 and P2 must be in VMS comparison date format:"
$ write sys$output " YYYY-MM-DD HH:MM:SS.CC (Omitted trailing fields are assumed zero)"
$ write sys$output " For example: @TIMEDIFF ""1999-12-31 23:59:59"" ""2000-01-01 00:00:01"""
$ write sys$output " Output is: (2000-01-01 00:00:01) - (1999-12-31 23:59:59) = 2 seconds"
$ exit
$ endif
$ call cvcdtjs 'p1'
$ mjdn1 = mjdn
$ ssm1 = ssm
$ call cvcdtjs 'p2'
$ ds = (mjdn - mjdn1)*86400 + (ssm - ssm1)
$ write sys$output "(",p2,") - (",p1,") = ",ds," seconds"
$ exit
$!-----------


--
Dale Dellutri -- ddel...@enteract.com

Bob Kaplow

unread,
Feb 25, 2000, 3:00:00 AM2/25/00
to
In article <893n5h$udv$1...@nnrp1.deja.com>, s...@mail.adldata.com writes:
> I need, in DCL, to subtract current datetime from a files
> created datetime to detemine how long the file has been
> around. I don't see any lexicals or other functions for it.
>
> Using DCL, i can parse the date time stamp, calculate individual
> differences and put it together to get the age of the file
> but i was hoping for something simpler.

Specifically, search for a DSIN article titled "Example-DCL How To Compute
Differences Between Two Dates/Times"

0 new messages