Register
It is currently Thu Jul 31, 2014 5:42 pm

Need script to manipulate the number of weeks in a month.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Mon Oct 06, 2008 1:40 pm   

Joined: Mon Oct 06, 2008 1:28 pm
Posts: 1
I am trying write a script which will take the number of weeks in a month and then provide the date for the Friday of that of that week.

For example - I have an input of "1990-07-04", where the last number is the numbered week in the month. This, for example is the 4th week of July 1990. I want to be able to calculate the date of the Friday of that week ( its is 1990/07/27 because I looked it up ).

In this example I suppose what it really needs to do is to calculate the day of the 4th Friday of July 1990.

Any help would be much appreciated.


Top
 Profile  
 PostPosted: Mon Oct 06, 2008 4:05 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
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 :)
Code:
#!/bin/bash
firstdate=$1
year=`echo $firstdate| cut -d"-" -f1`
month=`echo $firstdate| cut -d"-" -f2`
week=`echo $firstdate | cut -d"-" -f3`
w=0
let week=week+2  #adding 2 lines for cal output
for ind in `cal $month $year |sed s/\ /#/g`
  do
  wline=`echo $ind|sed s/#/-/g`
  let w=w+1
  if [ $w -eq 2 ]; then
  echo $wline
  fi
  if [ $w -eq $week ]; then
  echo $wline
  fi

  done



Code:
myownshadow@etch:~$ ./dateit.sh 1990-07-04   #yep your example
Mo-Sa-We-Th-Fr-St-Su
16-17-18-19-20-21-22   
#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.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP