1748205 Members
4524 Online
108759 Solutions
New Discussion юеВ

Re: DCL question

 
SOLVED
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.
11 REPLIES 11
Volker Halle
Honored Contributor
Solution

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)'"

Volker.
The Brit
Honored Contributor

Re: DCL question

or,

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

Dave
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.
Thanks.
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.

fwiw

Proost.

Have one on me.

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

Re: DCL question

karthikeyan,

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:

$ date=F$FAO("!UL-!AS-!4AS",F$INTEGER(F$EXTRACT(6,2,jdate)),F$ELEMENT(F$EXTRACT(4,2,jdate),"|","|JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|"),F$EXTRACT(0,4,jdate))

To get DAY, MONTH and YEAR as numbers:

$ DAY=F$INTEGER(F$CVTIME(DATE,,"DAY"))
$ MONTH=F$INTEGER(F$CVTIME(DATE,,"MONTH"))
$ YEAR=F$INTEGER(F$CVTIME(DATE,,"YEAR"))

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
Hoff
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
Advisor

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.