Pass date (YYYY-MM-DD) as parameter and get Day

Hi,

I have a requirement where I have to pass Date to a script and get the day from it.

Ex If parameter is 2015-09-29
The output should be Tuesday.

Can you please tell me how to get that?

You're a bit sparse with info about your system and what commands are available in what versions. Try

date -d"2015-09-29" +%A
Dienstag

Hi,

It doesnt seem to recognize -d option. Below is the output.
Please Let me know what information you are looking for. I'll add that if that helps.
It is a SOLARIS OS with bash running on it.


date -d"2015-09-29" +%A

date: illegal option -- d
date: illegal option -- 2
date: illegal option -- 0
date: illegal option -- 1
date: illegal option -- 5
date: illegal option -- -
date: illegal option -- 0
date: illegal option -- 9
date: illegal option -- -
date: illegal option -- 2
date: illegal option -- 9
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

How about telling us your OS, shell, and date version?

Hi,

Below is the information. Let me know if you need more info.

Shell is Bash.

$uname -a
SunOS sjcapp54 5.10 Generic_150400-11 sun4v sparc sun4v
 
$uname -r
5.10

$uname -m
sun4v
echo "2015-10-01" | perl -ne 'use POSIX qw(strftime);@y=split("-");print strftime("%A",0,0,0,$y[2],$y[1]-1,$y[0]-1900);'
1 Like

Thanks balajesuri.

It works perfectly. I did go through the usage of POSIX/ strftime to understand why you have used -1 for $y[1] (Month) and was able to get the answer.

Thanks again for your help. :slight_smile: