Get the date of monday when running from Friday to next Thursday


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the date of monday when running from Friday to next Thursday
# 1  
Old 02-25-2010
Bug Get the date of monday when running from Friday to next Thursday

Hi,
I have a requirement where I want to get the date of monday when I am running the script from previous Friday to the following Thursday.

For example: When ever I run the script between 19thFeb2010(Friday) to 25th Feb 2010(Thursday), I should get the date of 22nd Feb 2010 in the format of 'mm/dd/yyyy'.

Can any one please help me out.

Thank in advance.
# 2  
Old 02-25-2010
I understood your requirement.I want to know whether you give the from and to date as input or not.If you give it as input,then explain me in which format you give those dates.
# 3  
Old 02-25-2010
what do u expect if the To date is 4thmarch2010 ( Thursday ) ,
# 4  
Old 02-25-2010
I am giving the system date in the format 'mmddyy'.
If we are running the script on 4th March 2010, it should give as '03/01/10'
# 5  
Old 02-25-2010
Are you expecting this,

Code:
cur=`date +"%u"`
if [ $cur -eq 1 ]
        then
        echo `date "+%m/%d/%Y" `
        elif [[ $cur -gt 4 || $cur -eq 0 ]]
        then
         case $cur in
                 0) echo `date "+%m/%d/%Y" -d "+1 day"`;;
                 5) echo `date "+%m/%d/%Y" -d "+3 day"`;;
                 6)echo `date "+%m/%d/%Y" -d "+2 day"`;;
         esac
        else
         case $cur in
                 2) echo `date "+%m/%d/%Y" -d "-1 day"`;;
                 3) echo `date "+%m/%d/%Y" -d "-2 day"`;;
                 4) echo `date "+%m/%d/%Y" -d "-3 day"`;;
         esac


        fi

# 6  
Old 02-25-2010
Hi Karthigeyan, Thanks for your reply.
But "date -d" option is not working in my server. It is saying '-d' as not a recognized flag. I am using AIX.
Can you guide me if there is any other way?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Red Hat

How to find/display out last Friday's date of the month?

Hello, Can you please help me find/display out last Friday's date of the month using command in Unix/Linux (3 Replies)
Discussion started by: sunnysthakur
3 Replies

2. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

3. Shell Programming and Scripting

Get Date of Previous and next Monday

Hi, I would like to know how to get Previous Monday and Next Monday from the current date.. thanks (5 Replies)
Discussion started by: balasubramani04
5 Replies

4. UNIX for Dummies Questions & Answers

Can we get every tuesday or monday's date for the current week

Hi Can we get every tuesday or monday's date for the current week ? For the current week i need tuesday's date or monday's date in %m%d%y fromat Thanks (5 Replies)
Discussion started by: laxmi131
5 Replies

5. UNIX for Dummies Questions & Answers

crontab schedule - first thursday of every month

Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once... (2 Replies)
Discussion started by: paulds
2 Replies

6. UNIX for Advanced & Expert Users

Extract Monday from given date

Hi I want to extract the date on Monday depending upon the user input for that week. For example if the input date is 20080528 then the output should be 20080526. If the input is 20080525 then it will be 20080519 i am working on IBM AIX Thanks (2 Replies)
Discussion started by: itsme_maverick
2 Replies

7. UNIX for Advanced & Expert Users

get date of Thursday of any week

I need to be able to use a date in this format yyyymmdd to return the date of the Thursday of that week in the same format. Appreciate any help! (2 Replies)
Discussion started by: Miller
2 Replies

8. UNIX for Dummies Questions & Answers

I wanted to get the date of the first monday of a month.

Hi, I need to display the date of the first monday of a month. Can any one please help me on this. Thanks in advance. (6 Replies)
Discussion started by: Sheethal
6 Replies
Login or Register to Ask a Question