![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Create a script using DATE command? | thecoffeeguy | Shell Programming and Scripting | 1 | 05-15-2008 03:33 PM |
| want to create directory with the previous date | sridhusha | Shell Programming and Scripting | 7 | 11-19-2007 02:44 AM |
| need to create a file with its name having system date | hamsa | Shell Programming and Scripting | 11 | 10-18-2006 01:48 AM |
| Order files by create date | mab_arif16 | Shell Programming and Scripting | 4 | 05-15-2006 10:04 AM |
| Directory create date | Bab00shka | UNIX for Dummies Questions & Answers | 2 | 06-29-2005 07:42 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Use Perderabo's datecalc script -- http://www.unix.com/showthread.php?s...6559#post16559. It's as easy as:
Code:
> datecalc -D 1960 12 31 Saturday |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
datecalc uses ksh. Just chmod +x the datecalc script and run it as
Code:
datecalc -D 1960 12 31 |
|
#5
|
|||
|
|||
|
Python alternative
Code:
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
Code:
/home> python test.py 19 10 2006 Thursday |
|
#6
|
||||
|
||||
|
With GNU date command :
Code:
date --date="20061019" '+%A' Jean-Pierre. |
|
#7
|
|||
|
|||
|
Code:
perl -e '@y=localtime(time()-86400);printf "%04d-%02d-%02d",$y[5]+1900,$y[4]+1,$y[3];' |
|||
| Google The UNIX and Linux Forums |