![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Capture of month | Rafael.Buria | Shell Programming and Scripting | 2 | 01-10-2008 07:44 AM |
| How to match month | Nayanajith | Shell Programming and Scripting | 1 | 06-27-2006 01:55 AM |
| The last day of the last month | emily79 | Shell Programming and Scripting | 2 | 09-09-2005 09:54 AM |
| last day of the month | aya_r | Shell Programming and Scripting | 4 | 08-23-2005 12:26 AM |
| Write a shell script to find whether the first day of the month is a working day | phani | Shell Programming and Scripting | 7 | 03-18-2005 01:59 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Get Last working day of the month
Hi
I need a script to get "Last working day of the month". I will pass the month and year as parameters and i need to get the last working date. Ex for June 2008 the last working day is 30th its monday. for August 2008 the last working day is 29th and it is Friday. ie the last working day falls in Monday to Friday. Thanks for the help. Last edited by manmarirama; 06-03-2008 at 03:02 PM.. |
|
||||
|
The only useful Google result I could find was this, but then, it's actually pretty useful. Scroll down to the end for the grande finale. crontab(s) for the last "work-day" of every month [Archive] - The macosxhints Forums
|
|
||||
|
I would try something like this:
Code:
cal | awk '/^.[0-9]/{nf=NF;Date=$NF}
END{print nf, Date}'
2 30
if nf is between 2 and 6 (representing Monday thru Friday), there is your end of month. if nf is 1 or 7, that represents Sunday and Saturday, respectively, so adjust the Date according. Should be a snap. |
|
||||
|
With GNU date (coreutils) and bash:
Code:
#!/bin/bash
export LC_ALL=C
m=$(($1+1))
i=1
lastwday=$(date "+%w" --date "2008/$m/01 -$i days")
while [[ "$lastwday" < 1 ]] || [[ "$lastwday" > 5 ]];do
((i++))
lastwday=$(date "+%w" --date "2008/$m/01 -$i days")
done
dtelastwday=$(date --date "2008/$m/01 -$i days")
echo "The last working day of 2008/$1 is $dtelastwday"
exit 0
Code:
$ script-name 8 > The last working day of 2008/8 is Fri Aug 29 00:00:00 CEST 2008 |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|