Last sunday of current date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Last sunday of current date
# 1  
Old 03-14-2011
Last sunday of current date

Hi

Please help me with this problem

i need to find the date of last week sunday from the current given date
# 2  
Old 03-14-2011
Assuming you want the last sunday of the current month:
Code:
cal | awk 'NR==1{$1=$1;m=$0}$1{d=$1}END{print d, m}'

# 3  
Old 03-14-2011
this is what are you looking for ? Take month and year separate from you date.
Code:
cal $mon $year | awk -v v1=$mon -v v2=$year 'NF>1{a=$1} END{print a v1 v2}'

# 4  
Old 03-14-2011
hiii


first of all thanks a lot for reply

my question is


suppose my week starts from

sunday to saturday

so i am on any given date it should return me the last week sunday date

please help me on this
# 5  
Old 03-14-2011
Post your input date format.
# 6  
Old 03-14-2011
hiii
the input date format should be in year month day

like 20110314
# 7  
Old 03-14-2011
Try this,
Code:
mon=$(echo "20110314"|cut -c5-6)
year=$(echo "20110314"|cut -c1-4)
cal $mon $year  | awk -v v1=$mon -v v2=$year 'NF>1{a=$1} END{print a v1 v2}'
27032011

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

3. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

4. UNIX for Dummies Questions & Answers

Yesterday's Date if it is Sunday

Hi All, Can you please let me know how to get the yesterday's date of the given date if the given date is Sunday? I can't use GNU. I have the code to get the yesterday's date based on the system date. Thanks (5 Replies)
Discussion started by: shash
5 Replies

5. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

6. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

7. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

8. Shell Programming and Scripting

recurrence for every sunday for Date::MAnip in perl

Hi, I have a requirement to define all Saturdays/Sundays of every month in a year as holidays. I am making use of Date::Manip package available in perl. I tried writing a recurrence as : 0:1*3:7:0:0:0 --> this relation helps me to define 3rd Sunday of a year as sunday. My requirement is... (1 Reply)
Discussion started by: harpreetanand
1 Replies

9. UNIX for Dummies Questions & Answers

How to find last sunday (date) using perl?

How to find last sunday (date) using perl? Eg, If i run today (26-Feb-2008 / Tuesday), I should get 24-Feb-2008 (Sunday). Any help? (3 Replies)
Discussion started by: deepakwins
3 Replies

10. Shell Programming and Scripting

Date - Last Sunday thru Saturday

Hi All, I have to kick off a script on every Monday to get some data from database for last week (Sunday thru Saturday). If its Monday (12/12/2005) Begin date will be Sunday - 12/4/2005 End date will be Saturday - 12/10/2005 The script might not kick off on some Mondays. So my... (2 Replies)
Discussion started by: skymirror
2 Replies
Login or Register to Ask a Question