Calculating 7 days ago date for the given Argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating 7 days ago date for the given Argument
# 8  
Old 07-01-2011
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?
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 07-01-2011
Hi,

I have tested the below script in a different box and the version of date is :

Code:
$ 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.


Perfect this is working now:

Code:
#!/bin/sh
Day=`date -d '20110701 - 7 days' +%Y%m%d`
echo $Day

Code:
 ./date.sh
20110624

But,

When I am trying to execute the same script in a different box:

Code:
$ 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:
Code:
$ ./date.sh
20110708

Not sure why this is happening but wanted to know.

Really appreciate your quick responses and Thank you very much.

Last edited by rbatte1; 07-05-2016 at 04:57 AM.. Reason: Code tags
# 10  
Old 07-02-2011
That version of GNU date is 9 years out of date.
# 11  
Old 07-02-2011
try this..
Code:
$ date +%Y%m%d
20110702
$ TZ=CST+144 date +%Y%m%d
20110626
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get a given date and subtract it to 5 days ago

Hi all, I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for. # curl --proxy... (4 Replies)
Discussion started by: nms
4 Replies

2. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. UNIX for Advanced & Expert Users

N days ago

Hi, the following gives today $(date '+%d%m%y') For example 210111 for today (21 of january 2011). How can I have n days ego ? For example 160111 for 5 days ego ? thank you. (3 Replies)
Discussion started by: big123456
3 Replies

4. UNIX for Dummies Questions & Answers

Clarification on '1 days ago' in date command [Found answer, posted within]

I know the topic of getting yesterday's date has been covered ad nauseum, but I just want to be clear on something. I recently started using the command date --date='1 days ago' '+%m/%d/%y' to get yesterday's date and it's been working great. I just want to be certain that it is going to... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

5. Shell Programming and Scripting

Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' | Please use code tags (7 Replies)
Discussion started by: freddie999
7 Replies

6. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

7. Shell Programming and Scripting

date for two days or 3 days ago

i need a script that can tell me the date 2 days ago or 3 days ago. please help (7 Replies)
Discussion started by: tomjones
7 Replies

8. Shell Programming and Scripting

Find the file from 15 days ago

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (2 Replies)
Discussion started by: YoungBlood
2 Replies

9. UNIX for Dummies Questions & Answers

file was created before 15 days ago.

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (1 Reply)
Discussion started by: YoungBlood
1 Replies

10. Shell Programming and Scripting

Function 7 days ago

Please tell me how can I wirte a function to return the date 7 days ago by using calendar command? :confused: (2 Replies)
Discussion started by: LAY
2 Replies
Login or Register to Ask a Question