0

I need to pull the day given a specific date. For example, I will provide the date format of 2021_11_06 and the shell will provide "Sat" without quotes.

I know that I can get the current day by: $ date '+%a'

However, I need to provide the day given a specified date.

Thank you in advance for your input.

user2654953
  • 221
  • 1
  • 3
  • 11
  • What OS or version of date? On Mac you can do something like `date -j -f"%Y%M%d" "20211106" '+%a'`, but I think it will be different for GNU. – EdmCoff Nov 05 '21 at 15:51
  • Sun OS Oracle Solaris 10 1/13 I tried the following without success: date -j -f '%Y_%m_%d' "2021_11_06" +'%a' – user2654953 Nov 05 '21 at 16:01
  • I don't think Solaris' built-in `date` has a `-d` option like GNU, but there are some good options at https://stackoverflow.com/questions/6508819/convert-date-formats-in-bash. The `awk` solution might be a good place to start since it avoids the differences in `date`. – EdmCoff Nov 05 '21 at 16:06
  • The -d option is not availabel to Solaris. I will take a look at awk. – user2654953 Nov 05 '21 at 16:50
  • I do not have a Solaris with me right now, but there are a lot of gnu utilities under /usr/ucb (or they can be installed there). Maybe date is one of those? – Nic3500 Nov 06 '21 at 21:18

0 Answers0