Hi- To find the no of mondays in a given month
Moderators: chulett, rschirm, roy
Hi- To find the no of mondays in a given month
Hi How can we find the no of months in a given month in datastage parallel job. The date is not hardcoded,
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Probably the easiest is to create a routine the tests the first day of the month and the last day of the month to determine what day of the week each is, and to calculate the number of Mondays from that.
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Routines for parallel jobs are not written in DataStage BASIC; they are written in C++.
Algorithm Design
1. Determine weekday of first day of month.
2. Determine weekday of last day of month.
3. Determine number of days in month.
4. If number of days in month = 28 then Number of Mondays = 4.
5. If number of days in month = 29 then If first of month is Monday then Number of Mondays = 5 else Number of Mondays = 4.
... and so on.
Algorithm Design
1. Determine weekday of first day of month.
2. Determine weekday of last day of month.
3. Determine number of days in month.
4. If number of days in month = 28 then Number of Mondays = 4.
5. If number of days in month = 29 then If first of month is Monday then Number of Mondays = 5 else Number of Mondays = 4.
... and so on.
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.
You can call the follwon command line to do it. A bit crude, but it works:
cal jan 2008 |cut -c 4-5 |grep "[0-9]" |wc -l
*Note, cal jan 08 will give you Janury 8 AD, not 2008![Smile :)](./images/smilies/icon_smile.gif)
cal jan 2008 |cut -c 4-5 |grep "[0-9]" |wc -l
*Note, cal jan 08 will give you Janury 8 AD, not 2008
![Smile :)](./images/smilies/icon_smile.gif)
-------------------------
https://www.ssa.co.za
https://www.ssa.co.za
:D Very nice. For HP-UX (and perhaps others) it would need to be:
Now just run a year or more's worth into a hashed file and you'd be all set.
Code: Select all
cal 1 2008 |cut -c 4-5 |grep "[0-9]" |wc -l
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
To get around weirdness with space formatting, you can always use:
cal 1 2008 |cut -d " " -f 2| grep "[0-9]" |wc -l
cal 1 2008 |cut -d " " -f 2| grep "[0-9]" |wc -l
-------------------------
https://www.ssa.co.za
https://www.ssa.co.za
No need for a lot of effortchulett wrote: Now just run a year or more's worth into a hashed file and you'd be all set.
Code: Select all
for years in 2008 2009 2010; do for months in `seq 1 12`; do echo $years-$months| tr "\n" "|" ; cal $months $years |cut -d " " -f 2| grep "[0-9]" |wc -l ; done; done > dates.txt
-------------------------
https://www.ssa.co.za
https://www.ssa.co.za
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
That is not your requirement, because the number of Mondays in July can vary over the years: it may be four, it may be five. Your actual requirement is to determine the number of Mondays in July of the year mentioned in the date. The solutions above can yield this.
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.