From a given date in %m-%d-%Y
format we should determine what day it is.
Example: for the date 09-01-2017
output should be Friday
%r – Displays 12-hour clock time (01-12) using the AM-PM notation; in the POSIX locale, it is equivalent to %I:%M:%S %p. %S – Displays the seconds as a decimal number (00 – 59). %T – Displays the 24-hour clock (00-23) in the format equivalent to HH:MM:SS.
Very simple. Just use the date command itself with correct options.
$ date -j -f '%m-%d-%Y' "09-01-2017" +'%A'
Friday
If you have your date like this:
d="09-01-2017"
you need to reformat it to "YYYY-MM-DD"
date -d $(echo $d|awk -F- '{print $3 "-" $1 "-" $2}') +%A # DOW
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With