actually all date, time commands that i know works on week of year logic. But your request asks week of month.
so i wrote few lines over bash cal command. well it makes some difference with your calculation cos cal logic says weeks begin at monday
year=`echo $firstdate| cut -d"-" -f1`
month=`echo $firstdate| cut -d"-" -f2`
week=`echo $firstdate | cut -d"-" -f3`
let week=week+2 #adding 2 lines for cal output
for ind in `cal $month $year |sed s/\ /#/g`
wline=`echo $ind|sed s/#/-/g`
if [ $w -eq 2 ]; then
if [ $w -eq $week ]; then
myownshadow@etch:~$ ./dateit.sh 1990-07-04 #yep your example
#u can see it results 20 not 27 cos u dont calculate first half week
with some nifty hacking on parsing may lead u what u want.