Function to get day of week from YYYY-MM-DD date

Can't find out how to get the day of the week from a given date, anyone got a code snippet that could help please?

Ta!!

echo "Enter date ([YY]YY-MM-DD) : "
read DD
# choose from one of the lines below
date --date $DD +%A # DOW complete
date --date $DD +%a # DOW abreviated
date --date $DD +%u # DOW (1..7) 1 is monday
date --date $DD +%w # DOW (0..6) 0 is sunday

To put the result in a variable, use the command expansion $( ... )

That is limited to the GNU version of date, and will not work with any other version.

It can also be accomplished with the shell functions from The Dating Game.

if you have perl...

YEAR=2009
MM=11
DD=02
DOW=$(perl -e 'use Time::Local;
       @abbr = qw( Sun Mon Tue Wed Thu Fri Sat );
       $DATE = timelocal(0, 0, 0, $ARGV[2], $ARGV[1]-1, $ARGV[0]-1900);
       $DAY = (localtime $DATE)[6];
       print "$abbr[$DAY]\n";' $YEAR $MM $DD)
echo Day of week is: $DOW

Ta all!

Sorted!