System Date for first and last day of the month

Post Reply
User avatar
rahulsehgal
Nouveau
Nouveau
Posts: 148
Joined: 19 Mar 2009 12:00
Location: Delhi
Contact:

System Date for first and last day of the month

Post by rahulsehgal » 29 Nov 2012 10:07

Dear team,

I am trying to pass the date variable to my Control-M jobs, where i need to pass first day of the last month and last day of the last month in the job command line in format MMDDYYYY

this job will be running on Ad-hoc basis and doesnot have any defined scheduling date.

Please let me know if there is any way to perform above action in Control-M Job definition using auto edit variable or any other variable usage.

Regards.
Rahul Sehgal

User avatar
mauriziog
Nouveau
Nouveau
Posts: 807
Joined: 08 Jun 2007 12:00
Location: Varese - Italy
Contact:

Post by mauriziog » 29 Nov 2012 9:44

Yes you can do that, is a usual need.
You may use the %%CALCDATE function and the %%SUBSTR function.
The calculation are based on the %%ODATE or %%$ODATE variable.

I write here the sintax of functions, so you can try to solve the problem; then we can compare the solutions: ok ?

Calcdate
result=%%CALCDATE date +|-quantity
Example:
%%A=%%CALCDATE %%DATE -2

substr
result=%%SUBSTR variable startpos length

Example:
%%Number=%%SUBSTR %%Nstring %%Start 3
if Nstring=123456789 and start=3 lenght=4
Number=4567

(from Parameter Guide pag. 520-521)

Regards

User avatar
mauriziog
Nouveau
Nouveau
Posts: 807
Joined: 08 Jun 2007 12:00
Location: Varese - Italy
Contact:

Post by mauriziog » 03 Dec 2012 9:33

Yere one solution in the date format YYYYmmDD:

in set panel:
data1=%%$CALCDATE %%$OYEAR.%%OMONTH.01 +32
data2=%%$CALCDATE %%$OYEAR.%%OMONTH.01 +62
sub1=%%SUBSTR %%data1 1 6
sub2=%%SUBSTR %%data2 1 6
LastDay=%%$CALCDATE %%sub2.01 -1
FirstDay=%%sub1.01


The echo of variables calculated as above (job ordered on today date 20121203) is:
LastDay=20130131 FirstDay=20130101

The calcdate are done considering that must be valid all month, even for february.
You can change the data format using the SUBSTR function.

Regards

User avatar
rahulsehgal
Nouveau
Nouveau
Posts: 148
Joined: 19 Mar 2009 12:00
Location: Delhi
Contact:

Thank for the help here.

Post by rahulsehgal » 03 Dec 2012 11:08

Thanks Mauriziog for the help here, above given solution worked

Post Reply