March 6th, 2012, 09:35 PM
Help Requested - how to find last Sunday's date if a date is given
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.
March 8th, 2012, 03:03 PM
Thanks for taking a glance of the issue.
I have found a solution for this as below,
export DAYS_AGO=`date +%w`
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.
March 8th, 2012, 09:10 PM
Thanks for posting your solution.
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
March 23rd, 2012, 06:41 AM
The date command is *way* more powerful than having to go through all of that though:
date -dlast-sunday +%Y%m%d