Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I get a weekday for any date using shell script

Status
Not open for further replies.

lutech

Programmer
Jan 25, 2002
16
CA
If I have a date like 2002-04-20, how can I get the weekday of the day using shell script?

Thanks in advance,
 
Hi lutech ,
Here is just a sample . You have to copy the following script
below into a file . Then execute the file .

Sample Script begins as shown below :


# !/bin/ksh
echo " Week of the Month Computation "
echo " ====================== \n"
echo "Enter the Year-Month-Date format :\c"
read user_input

# Variables

Year_value=`echo ${user_input} | cut -d"-" -f1,1 `
Month_value=`echo ${user_input} |cut -d"-" -f2,2 `
Date_value=`echo ${user_input} |cut -d"-" -f3,3 `

# Call calendar

cal ${Month_value} ${Year_value} | grep -v -i [a-z] > tmp1
echo "week_1
week_2
week_3
week_4
week_5
" > tmp2

wk=`paste tmp2 tmp1 | grep ${Date_value} | awk -F" " '{print $1}' `


# Cleanup temporary files
if [ -f tmp1 -a -f tmp2 ]
then
rm tmp1 tmp2 ;
fi


# Output to user

echo " The week for ${user_input} shall be ${wk} "




#Rgds , omari



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top