: '
/*
* NAME : dayOfWeek - return the day of the week for a date
*
* USAGE : dayOfWeek
*
* ARGUMENTS : - Only accepts dates in the format DD MM YYYY
* where DD is in the rage 1-31
* MM is 1 (Jan) thru 12 (Dec)
* YYYY is 1753 - 9999
*
*
* DESCRIPTION : dayOfWeek returns the named day for any given date after 1753
*
* NOTES : 1753 is the year after the change to the Gregorian
* calendar - it gets really complex if you try to handle
* dates before this
*
* SEE ALSO : The Zeller Algorithm here is adapted from an example in "SQL for Smarties"
* by Joe Celko
*
*/'
dayOfWeek()
{
(
/usr/bin/bc <<!
define f(y, m, d) {
b = y;
a = m - 2;
if ( a <= 0 ) {
a = a + 12;
b = y - 1;
}
x = ((d + (13 * a - 1) / 5 + 5 * (b % 100) / 4 - 7 * b / 400) % 7) + 1;
return(x);
}
f($3, $2, $1)
!
) 2>/dev/null | while read VAL
do
case "$VAL" in
1)
/bin/echo "Sun"
;;
2)
/bin/echo "Mon"
;;
3)
/bin/echo "Tue"
;;
4)
/bin/echo "Wed"
;;
5)
/bin/echo "Thu"
;;
6)
/bin/echo "Fri"
;;
7)
/bin/echo "Sat"
;;
esac
done
}
exit 0

Last Updated