Operating System - OpenVMS
Showing results for 
Search instead for 
Did you mean: 

Re: DCL question

Go to solution
karthikeyan mahalingam
Occasional Advisor

DCL question

I have this written in a COM file

business_date = f$edit(p1,"trim,upcase")
begin_date = business_date
end_date = business_date

month = f$extract(4,2,business_date)
month = month -1

begin_date[4,2]= "''month'"
show symbol begin_date

on running this COM file, when the input is 20100321, the output is 20102 21.
what happens is month 03 - 1 = 2.
what should i do, if i need 02, instead of 2, to look the output as 20100221.
Volker Halle
Honored Contributor

Re: DCL question

With month = month -1 you convert month from a string symbol to a numeric symbol.

You need to use

$ begin_date[4,2]:="''F$FAO("!2ZL",month)'"

The Brit
Honored Contributor

Re: DCL question


$ If f$len(Month) .lt. 2 then Month = "0''Month'"

Graham Burley
Frequent Advisor

Re: DCL question

What's this date use for? Have you considered what happens when business_date is 20110121 or 20110331 ?
karthikeyan mahalingam
Occasional Advisor

Re: DCL question

Yes Graham,
I have taken care of these cases.
if the month 01, i change the year and month as well.
Jan van den Ende
Honored Contributor

Re: DCL question

karthikeyan mahalingam,

have you considered / do you have control over the inpt date format?
If you can input 2010031 as 21-mar-2010, then you have the full functionality of F$CVTIME available. Which includes all kinds of date reckoning.



Have one on me.

Don't rust yours pelled jacker to fine doll missed aches.
John Gillings
Honored Contributor

Re: DCL question


Rather than reimplement the convoluted logic of date calculations, I recommend you keep your dates in VMS ABSOLUTE format and use F$CVTIME to do the date arithmetic.

For example, the day before DATE is:

$ day_before=F$CVTIME("''date'-1-","ABSOLUTE","DATE")

Once you've found your target date, you can convert it to julian format with:

$ jdate=F$CVTIME(date,,"DATE")-"-"-"-"

Converting a julian date to an absolute date is:


To get DAY, MONTH and YEAR as numbers:


To convert DAY, MONTH and YEAR back to julian format, use F$FAO:

$ jdate=F$FAO("!4ZL!2ZL!2ZL",YEAR,MONTH,DAY)

In the control string for F$FAO "!" means a formatting directive follows, the next number is the field width and "ZL" means "Zero filled Longword integter"
A crucible of informative mistakes
Honored Contributor

Re: DCL question

And if you're going to be doing date math on your own (and if that local implementation can be avoided in favor of using system routines, then do avoid it), you will also get to deal with leap year and with the two daylight saving time changes.
karthikeyan mahalingam
Occasional Advisor

Re: DCL question

I am really overwhelmed with the answers posted. Thank you everybody for this wonderful forum community.
sathya prabu

Re: DCL question

i hope this will help

month_str = "00" + month

month_str =f$extract(f$length(month_str)-2,f$length(month_str),month_str)
! will always give two digits. if month is digit then 0 is displayed along els eif two, then only the two digit month number is dispalyed.