hello!
I need a date calculation script that need to do that:
./date.sh 20090312
and the script need to give me which day is it for example monday friday or what else!
can anyone help me?? its really urgent :S thx the help!
hello!
I need a date calculation script that need to do that:
./date.sh 20090312
and the script need to give me which day is it for example monday friday or what else!
can anyone help me?? its really urgent :S thx the help!
What have you tried so far?
that's the problem. i dont have any solution how i need to start. i have write this :
#!/bin/bash/
DATE=$(echo $1 |awk 'BEGIN{FIELDWIDTHS="4 2 2"}{print $1 RS $2 RS $3 }')
YEAR=$(echo $DATE | cut -d ' ' -f1)
MONTH=$(echo $DATE | cut -d ' ' -f2)
DAY=$(echo $DATE | cut -d ' ' -f3)
if [ $MONTH -gt 12 ];
then
echo "Wrong Month!!"
fi
if [ $DAY -gt 31 ];
then
echo "Wrong Day!!"
fi
but this only check the month and the day validation.
What Operating System and version do you have?
uname -a
What Shell do you use?
echo $SHELL
And more specifically:
Do you have "perl"?
Do you have the GNU date package?
What is the normal value of your timezone?
echo $TZ
We know what your input looks like and can guess that your input date format is YYYYMMDD , but what output are you looking for? A numeric day of week (Sunday=0) or a character representation like "Wed" or "Wednesday" or whatever?
just need to write that for output wed or sun...!
---------- Post updated at 08:50 AM ---------- Previous update was at 08:49 AM ----------
and yes my input date format is yyyymmdd
Assuming you are on a GNU/Linux platform:
$ date +%a --date "20090312"
Thu
solved thx
Perl
perl -le 'use Time::Local;%day=(0=>Sun,1=>Mon,2=>Tue,3=>Wed,4=>Thu,5=>Fri,6=>Sat);$dt=20090312;
@flds=unpack("A4 A2 A2",$dt);
$flds[0]-=1900; $flds[1]-=1;
$sec=timelocal(0,0,0, $flds[2], $flds[1], $flds[0],0,0,0);
@dateflds=localtime($sec);print $day{$dateflds[6]};'
Is there any other way in perl ?