Operating System - OpenVMS
1825768 Members
2042 Online
109687 Solutions
New Discussion

Lexical functions f$time()

 
SOLVED
Go to solution
geir_2
Super Advisor

Lexical functions f$time()

Hi,

Is it possible to let f$time write 01, insted of " 1" (leading blank characters)??. I looked at f$cvtime, but could not find any solutions.

I want to include a daynumber in a filename, so blank characters make problems.

Thanks
9 REPLIES 9
Ian Miller.
Honored Contributor
Solution

Re: Lexical functions f$time()

It appears that F$TIME, F$CVTIME, F$FAO and so on generate a string with a leading space instead of a 0 eg. 1-NOV-2005.

However you can format this yourself

$ now = F$TIME()
$ d = F$INTEGER(F$CVTIME(now,"ABSOLUTE","DAY"))
$ m = F$CVTIME(now,"ABSOLUTE","MONTH")
$ y = F$CVTIME(now,"ABSOLUTE","YEAR")
$ WRITE SYS$OUTPUT F$FAO("!2ZL-!AS-!AS",d,m,y)
____________________
Purely Personal Opinion
David Jones_21
Trusted Contributor

Re: Lexical functions f$time()

The comparison output format of f$cvtime() does what you want:
$ day = f$cvtime(f$time(),"COMPARISON","DAY")

I'm looking for marbles all day long.
Hein van den Heuvel
Honored Contributor

Re: Lexical functions f$time()


I realize the problem is solved. The comparision time is always my preferred solution as it sorts. but for similar problems elsewhere you may consider the little used/known left assignment in DCL:

$ x = f$time()
$ if f$loc(" ",x).eq.0 then x[0,1]="0"

that is...

If the first found space in X is at offset 0, then make 1 byte at offset 0 be an ascii 0.

fwiw,
Hein.
Ian Miller.
Honored Contributor

Re: Lexical functions f$time()

$ if f$loc(" ",x).eq.0 then x[0,1]="0"
%DCL-W-IVCHAR, invalid numeric value - check for invalid digits
\0\

replace "0" by ascii code for 0
____________________
Purely Personal Opinion
Hein van den Heuvel
Honored Contributor

Re: Lexical functions f$time()


Oops, retype error. Thanks for pointing that out Ian.
The line should be:

if f$loc(" ",x).eq.0 then x[0,1]:="0"

I hate re-typing and always cut&paste from working examples, but I was experimenting with a new 'T5515 thin client' at home and could not get the Xterm cut&paste to go. Argh.

The := is a string assignment.
The alternative is just the var[off,len]=val for left bit string assignments.

The suggested solution then becomes:

if f$loc(" ",x).eq.0 then x[0,8]=48

Notice the 8 for 8 bits in a byte.

Hein.



Mike Reznak
Trusted Contributor

Re: Lexical functions f$time()

Hi,

just another way.

$ zz = f$cvtime(,"ABSOLUTE")
$ if f$length(f$ele(0," ",zz)).eq.10 then zz = "0''zz'"

Mike
...and I think to myself, what a wonderful world ;o)
Hein van den Heuvel
Honored Contributor

Re: Lexical functions f$time()

Right... f$cvtime(,"absolute") does not have a leading space, where f$time() does.

Instead of the 'heavy' f$elem construction, Mike could also have just tested length:

$ if f$len(zz)).eq.22 then zz = "0" + zz


With the leading space from f$time() you would need:

$ x=f$time()
$ show symb x
X = " 1-NOV-2005 11:31:10.88"
$ if f$extr(0,1,x).eqs." " then x = "0" + f$ext(1,99,x)
$ show symb x
X = "01-NOV-2005 11:31:10.88"
$

I think we now have sufficiently beaten this horse to death :-).

Hein.


Ian Miller.
Honored Contributor

Re: Lexical functions f$time()

isn't one of the perl mottos - There is always more than one way to do it


:-)
____________________
Purely Personal Opinion
Mike Reznak
Trusted Contributor

Re: Lexical functions f$time()

Hein,
that's even better.
I wasn't shure, if there is 0 preceding morning hours in the string. That's why I've suggested F$ELEMENT.

Mike
...and I think to myself, what a wonderful world ;o)