Yesterday's Date Help!

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Yesterday's Date Help!

Post by cyclogenisis »

I'm running a shell script through the EXEC stage. The command requires yesterday's date in YYYYMMDD format in part of the shell script. How can I get a user variable/job parameter with yesterdays date in the format so it can be used in this stage?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Just want to make sure I understand - you need to get yesterday's date from the UNIX command line?

If so, then this is the trick you'll find if you google:

Code: Select all

`TZ=MST+24 date +%Y%m%d`
Use your timezone. If that's not what you need then please clarify.
-craig

"You can never have too many knives" -- Logan Nine Fingers
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

No as a variable or parameter in datastage. That can be used in other stages.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Still not clear... if it needs to be a job parameter so it can be "used in other stages" who/what is responsible for fetching or setting the value? Does "other stages" mean in a Sequence job? Other stages in a PX job? And what in the heck does this have to do with the script? :?

Easy enough to write a custom routine to get the system date, subtract 1 from it and then format it into a YYYYMMDD string in a Routine Activity stage. Then a sequence job can pass the value downstream to a job parameter in a Job Activity stage that runs the job that needs it.

If I'm still not helping, you need to be as specific as possible as to what it is you need so I can stop floundering around here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
FranklinE
Premium Member
Premium Member
Posts: 739
Joined: Tue Nov 25, 2008 2:19 pm
Location: Malvern, PA

Post by FranklinE »

Our "yesterday" date requirement is for the previous business day. I solve this simply by putting the date in a file. I have an after-job routine that updates the file with "today's" date to be used the next time the jobs run. I use echo and the parameter that has the current date in it.

To read the date, I use the Execute Command sequence stage to run a "cat" command on the file, then a user variable stage to place the CommandOutput into a variable I can pass to the parallel job. I use the following in the derivation for the user variable to avoid control character problems:

Code: Select all

Convert(@FM,"", GET_PREV_DATE.$CommandOutput)
Franklin Evans
"Shared pain is lessened, shared joy increased. Thus do we refute entropy." -- Spider Robinson

Using mainframe data FAQ: viewtopic.php?t=143596 Using CFF FAQ: viewtopic.php?t=157872
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

Will try to be more clear.

Currently, I have a ExecCommand stage which executes a simple shell command. Here is an example for test purposes:

echo "#UserVariables_Activity_5.Date#,2,3,4,5,6" > /somepath/test_1.csv

I would like the parameter or variable (it doesn't matter which) #UserVariables_Activity_5.Date# to be yesterday's date in YYYYMMDD format. Is the way you described in the last post the easiest way of getting this done, when you speak of custom routine are you talking about the routine stage? Sorry I am newer to datastage and working on my first project.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

In the controlling sequence you can use

Code: Select all

Oconv(Date() - 1, "DYMD[4,2,2]" : @VM : "MCN")
Date() always uses the current date. If you prefer, use system variable @DATE instead, which is set to the job start date.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

Ray you are awesome. Thank you very much for your help, if I was a bit more clear to start we could have saved ourselves some typing.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I never got a chance to be awesome. :cry:
-craig

"You can never have too many knives" -- Logan Nine Fingers
cyclogenisis
Premium Member
Premium Member
Posts: 48
Joined: Wed Jan 07, 2015 3:30 pm

Post by cyclogenisis »

You were equally as awesome. Thanks very much for your time!
Post Reply