Web page archived as of 2018-05-22. Some links & features might not work.

Calculate Sysadmin day dates

System Administrator Appreciation Day, also known as Sysadmin Day, SysAdminDay, SAD or SAAD, is an annual event (…) to show appreciation for the work of sysadmins and other IT workers. It is celebrated on the last Friday in July.1)

I did a bit of research of how to calculate the last Friday of July for any given year. My own solution was to use ncal and sed or awk:

$ YEAR=2015; ncal 7 $YEAR | awk '/^Fr/{print $NF}'

That's the shortest code I could find. ncal delivers a calender of the whole month. awk then prints the last entry of all Fridays. The same can be achieved with sed, of course:

$ YEAR=2015; ncal 7 $YEAR | sed -n 's/^Fr.* \([^ ]\+\) *$/\1/p'
$ YEAR=2015; ncal 7 $YEAR | sed -nr 's/^Fr.* ([^ ]+) *$/\1/p'   # GNU Sed

Note that the output of ncal and colleagues depends on your locale. Consider prepending LC_ALL=C or whatever fits. So, in Bash this could become LC_ALL=C ncal 7 $YEAR.

Another very nice trick was provided by cbuckley using date. However, it's a bit less obvious ;-)

$ YEAR=2015; date -d${YEAR}0801-$(date -d${YEAR}0801+2days +%u)days +%d

To my surprise, PHP's strtotime is capable of parsing "last Friday of this month" (contrary to GNU date):

$ php -r 'echo date("d", strtotime("last fri of July 2015"))."\n";'

Once I was finished with my own humble attempts I found Last Friday of each month - Rosetta Code ^_^

blog/140817_calculate_sysadmin_day_dates.txt · Last modified: 2014-08-17 13:55 by andreas