What is your system? What is your shell? This has a huge effect on the tools you have available for playing with dates. On some systems you can just date -d and print dates and timestamps for whatever time you want. Others might have awk or perl extensions for it. And a few obnoxious ones have no elegant way to handle it and must use an enormous ksh script to parse dates the hard way.
Linux xbdp5898pap 2.4.21-50.ELsmp #1 SMP Tue May 8 17:18:29 EDT 2007 i686 i686 i386 GNU/Linux
I am using Bash Shell.
Like if I use date -d then it would take the system date and then we can print wat we want.But Instead I would like to use the User's date(20110701) and then calculate the 7 days ago date (20110624) and print as an output.
Thanks for your thoughts. Really appreciate for your time.
Hmmm. That's weird. It works fine here, pasted keystroke for keystroke, and I've not encountered a version of GNU date before that didn't have it. You definitely have a working -d option, since the epoch time it printed is correct for that date.
What does date --version show you? I've got 8.5.
Maybe it just doesn't have @ for epoch seconds? That can be worked around using the syntax tukuyomi noticed. Does date -d '20110701 - 7 days' work?
I have tested the below script in a different box and the version of date is :
$ date --version
date (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
When I am trying to execute the same script in a different box:
$ date --version
date (coreutils) 4.5.3
Written by David MacKenzie.
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Result:
$ ./date.sh
20110708
Not sure why this is happening but wanted to know.
Really appreciate your quick responses and Thank you very much.