Need help to create a date script

So I need to create a shell script that can take as input a numeric day, month and year and output the day of the week for the input date.

So let's say, I input "programname 19 10 2006" it should output Thursday... I tried messing around with the grep and awk commands, but I can't get it to work.

I'd appreciate any help.

Use Perderabo's datecalc script -- days elapsed between 2 dates. It's as easy as:

> datecalc -D 1960 12 31
Saturday

So I tried to run the script named it Zoltar...

[elee@uxprod elee]$ bash Zoltar -D 1960 09 09
Zoltar: line 116: integer: command not found
Zoltar: line 81: integer: command not found
Zoltar: line 83: set: -A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Zoltar: line 91: ((: 09: value too great for base (error token is "09")
Zoltar: line 96: ((: 09: value too great for base (error token is "09")
Zoltar: line 110: print: command not found
Zoltar: line 123: ((: 09: value too great for base (error token is "09")
Zoltar: line 131: ((: 09: value too great for base (error token is "09")
Zoltar: line 135: print: command not found
Zoltar: line 142: integer: command not found
Zoltar: line 143: set: +A: invalid option
set: usage: set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
Zoltar: line 154: print: command not found

datecalc uses ksh. Just chmod +x the datecalc script and run it as

datecalc -D 1960 12 31

Python alternative

import sys,time
day,month,year = sys.argv[1:] #assume first param is day, then month, finally year
b = time.strptime("%s %s %s" % (day ,month, year), "%d %m %Y")
convert = time.strftime("%A", b)
print convert

output:

/home> python test.py 19 10 2006
Thursday

With GNU date command :

date --date="20061019" '+%A'

Jean-Pierre.

1 Like
perl -e '@y=localtime(time()-86400);printf "%04d-%02d-%02d",$y[5]+1900,$y[4]+1,$y[3];'