Last sunday of current date


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


thanks a lot all of ur reply

can u people please answer one more question

suppose i have week no , and i know day should be monday and i know year too

hw can i find the exact date of monday

please help me with this
# 9  
Old 03-14-2011
To bring little tweak to Pravin code :

Code:
set -- $(echo "20110314" | sed 's/\(..\)..$/ \1/')
cal $2 $1  | awk -v m=$2 -v Y=$1 'NF>1{d=$1} END{print d m Y}'

This User Gave Thanks to ctsgnb For This Post:
# 10  
Old 03-14-2011
hii


can u please answer this question


if i have the week number and i know monday is the day and i know year too

how can i find out the day of the week
please as this is very imp
# 11  
Old 03-14-2011
You could also get the yesterday date from the monday of the current week
# 12  
Old 03-14-2011
You can also use Korn Shell 93. It has built in date arithmetic.
Code:
$ printf "%T\n" "last sunday in month"
Sun Mar 27 00:00:00 EDT 2011
$ printf "%T\n" "last week sunday"
Sun Mar  6 00:00:00 EST 2011
$ printf "%T\n" "last sunday"
Sun Mar 13 00:00:00 EST 2011

# 13  
Old 03-14-2011
Code:
a=$(date +%w)
[[ $a -eq 0 ]] && a=7
ts=$(( $(date +%s) - $a * 24 * 3600 ))
date -d "1970-01-01 00:00:00 UTC + $ts seconds"

This is with GNU date

Code:
# date
lun mar 14 15:23:19 CET 2011
# a=$(date +%w)
# [[ $a -eq 0 ]] && a=7
# ts=$(( $(date +%s) - $a * 24 * 3600 ))
# date -d "1970-01-01 00:00:00 UTC + $ts seconds"
dim mar 13 15:23:24 CET 2011
# date
lun mar 14 15:23:33 CET 2011
#

or
Code:
# date -d "1970-01-01 00:00:00 UTC + $ts seconds" +%Y%m%d
20110313


Last edited by ctsgnb; 03-14-2011 at 11:30 AM..
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