Operating System - HP-UX
1753684 Members
5465 Online
108799 Solutions
New Discussion юеВ

Is today the last working day?

 
SOLVED
Go to solution
Ryan Clerk
Frequent Advisor

Is today the last working day?

Hello Experts,

I did a search and found some ideas about finding out if today is the last day of the month. I have a little tougher problem. I need to know if this is payday which our company defines as the last WORKING day of the month. For example, if March 29th is a Friday, the 30th is Saturday, and the 31st is Sunday then Friday the 29th is the last working day of the month even if it is not the last day of the month.

Points for any clues or solutions.

Please help, Ryan
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Is today the last working day?

Okay, no surprise, I'll pull out my date hammer. This should do it:

if [ $(caljd.sh -M) != $(caljd.sh -x 6 -x 0 -n 1 -M) ]
then
echo "This is the last working day of the month; I get paid!"
else
echo "It ain't payday"
fi

All we are doing is comparing today's month with
tomorrow's (-n 1) if we skip Saturdays (-x 6) and Sundays (-x 0).

If you do a search for caljd.sh (or caljd.pl), you should be able to find a copy. Version 2.05 is the latest. You can substitute caljd.pl for caljd.sh if you like; the arguments are identical.

That should fix you, Clay
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Is today the last working day?

Hi again Ryan,

Eventhough you didn't mention it, today might also be payday if tomorrow is a company holiday. I've got you covered there as well, if you've kept your /etc/acct/holidays file up to date.

One minor change will take into account holidays: Add the -h (skip holidays flag).

if [ $(caljd.sh -M) != $(caljd.sh -x 6 -x 0 -h -n 1 -M) ]
then
echo "This is the last working day of the month; I get paid!"
else
echo "It ain't payday"
fi

You can invoke caljd.sh -u for full usage.


If it ain't broke, I can fix that.
Michael Tully
Honored Contributor

Re: Is today the last working day?

Hi Ryan,

Clay's "Date Hammer" *will* fix virtually all scripts that are date related. (Mind you I've not found a situation where it hasn't!) We have implemented a number of scripts that include this tool and it is very handy.

(Had to give it a plug Clay!)

Cheers
Michael
Anyone for a Mutiny ?
Uday_S_Ankolekar
Honored Contributor

Re: Is today the last working day?

Over to Mr. Clay... with his great script.!!
Good Luck..
Rodney Hills
Honored Contributor

Re: Is today the last working day?

Here is another way using 'cal'. You can run it any day of the month and it will return the last friday of that month.

lastday=`cal | awk '$2!=""{last=$NF}END{print last}'`

--Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: Is today the last working day?

oops, I meant "working day", not "friday"

-- Rod Hills
There be dragons...
Ryan Clerk
Frequent Advisor

Re: Is today the last working day?

Wow! You guys are great! I had my first answer in under 10 minutes and I had been fighting this for two whole days! Clay, I hadn't dared to mention the company holidays because I "knew" that would be impossible.

Thanks to everybody, Ryan