Hi All,
I know my question is more of a LINUX command, but i thought i will check in this forum as I have seen lots of guys around with plenty of Scripting knowledge.
Here is the situation:
I have a file coming from MF every Sunday & my Master Sequencer runs any date between Tuesday to Friday of every week (Weekly process). Is there a command by which I can derive the Last Sunday's date based on CURR_BUSINESS_DATE & pass this value to read the files from MF.
Any thoughts will be very helpful.
Thanks in advance
Freddie
How to derive last sunday's date based on Current date
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
If you're generating a command line argument from a DataStage sequence an elegant expression is
This works because the internal date format (number of days since 1967-12-31) remainder after dividing by 7 is 0 for Sunday.
Code: Select all
Oconv(Date() - Mod(Date(),7), "D-YMD[4,2,2]")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
In Linux/UNIX, date arithmetic is not going to be as easy as using functions already built into DataStage. You can use the date command with format options, but subtracting days from a current date will pretty much force you to build your own calendar logic for going backwards across months and years. Leap years will be annoying too. To give an idea:
Weekday number with Monday being 1 and Sunday being 7:
$ date +%u
7
Weekday number, with Sunday being 0 and Saturday being 6:
$ date +%w
0
Sunday April 1, 2012 is a bad example to start with. If you find some utility or existing program for date arithmetic on Linux/UNIX, then it may become easy. I would stick with DataStage functions for this scenario. Suppose today were not Sunday and you used the weekday number to determine previous Sunday was 3 days ago, so you subtract 3 off the day of month, which is currently day 1 (1 minus 3 = -2):
Today's date formatted YYYY-MM-DD:
$ date +%Y-%m-%d
2012-04-01
Date subtraction from one month to previous month:
$ echo `date +%Y-%m-`$((`date +%d` - 3))
2012-04--2
Weekday number with Monday being 1 and Sunday being 7:
$ date +%u
7
Weekday number, with Sunday being 0 and Saturday being 6:
$ date +%w
0
Sunday April 1, 2012 is a bad example to start with. If you find some utility or existing program for date arithmetic on Linux/UNIX, then it may become easy. I would stick with DataStage functions for this scenario. Suppose today were not Sunday and you used the weekday number to determine previous Sunday was 3 days ago, so you subtract 3 off the day of month, which is currently day 1 (1 minus 3 = -2):
Today's date formatted YYYY-MM-DD:
$ date +%Y-%m-%d
2012-04-01
Date subtraction from one month to previous month:
$ echo `date +%Y-%m-`$((`date +%d` - 3))
2012-04--2
Choose a job you love, and you will never have to work a day in your life. - Confucius
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Why not go simple and have a CRON job echo the date to a text file. Concatinate the date to the file and have it execute first thing every Sunday.
That way you'll leave the OS dealing with any Daylight savings / Time Zone issues. You'll also have a history of dates to look at and potentially reprocess old data.
Your datastage job kickoff script would then read in the text file and pass in the date as a parm to your initial sequencer.
That way you'll leave the OS dealing with any Daylight savings / Time Zone issues. You'll also have a history of dates to look at and potentially reprocess old data.
Your datastage job kickoff script would then read in the text file and pass in the date as a parm to your initial sequencer.
Having been down this road already, I found the following useful:
Code: Select all
PreviousWeekdayFromDate([yyyy-mm-dd],"friday") -- returns date of named weekday.
WeekdayFromDate([yyyy-mm-dd]) -- returns integer, Sunday is 0.
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
"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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: