Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 6th, 2012, 09:35 PM
dsfreddie dsfreddie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 6 dsfreddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 49 sec
Reputation Power: 0
Help Requested - how to find last Sunday's date if a date is given

Hi All,

I have got a requirement for my project. It is as follows,

If I pass today's date as a parameter to a command/script, it should derive the previous Sunday's date. ( ie if 201200307 is passed, the command/script should return 20120304).

Is there a way we can do it ? I would prefer to use a command instead of a script. Any thoughts will be appreciated.

Thanks
Freddie

Reply With Quote
  #2  
Old March 8th, 2012, 03:03 PM
dsfreddie dsfreddie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 6 dsfreddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 49 sec
Reputation Power: 0
Thanks for taking a glance of the issue.

I have found a solution for this as below,

export DAYS_AGO=`date +%w`
echo $DAYS_AGO
export SUB_DATE=`date -d "-$DAYS_AGO day" "+%Y%m%d"`
echo "P_SUB_DATE=$SUB_DATE" >>$COMMON_TMP/CPMGDynamicDateFile.txt

I am not sure whether this command will work fine for all the dates of a month (like for e.g: 20120302). Will it give the correct date as expected.

Any thoughts will be much appreciated.

Thanks
Freddie

Reply With Quote
  #3  
Old March 8th, 2012, 09:10 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,238 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 7 m 57 sec
Reputation Power: 4445
Thanks for posting your solution.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
  #4  
Old March 23rd, 2012, 06:41 AM
this213's Avatar
this213 this213 is offline
D'oh!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: East Coast
Posts: 72 this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level)this213 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 15 h 10 m 28 sec
Reputation Power: 72
The date command is *way* more powerful than having to go through all of that though:
Code:
date -dlast-sunday +%Y%m%d

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Help Requested - how to find last Sunday's date if a date is given

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap