display all dates 200 days back


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display all dates 200 days back
# 1  
Old 08-12-2009
display all dates 200 days back

i need help! can someone help me please?
i try to calculate date under unix (ksh)...AIX operating system.

I have to find the date 200 days from today's date.
then the script should loop 200 times and display on command line every day's date until the current date.


example:

todays date: 2009-08-12
(calculate date 5 days from current date and loop and display until the date is current date)

Display:

2009-08-07
2009-08-08
2009-08-09
2009-08-10
2009-08-11

how can i do calculate?
i know that it is not possible with the date command!

Thanks in advance
Mark
# 2  
Old 08-12-2009
I hope this is not a class assignment..
Code:
#!/bin/ksh

ago()
{
   perl -e ' my $delta = $ARGV[0] * -1;
             @t=localtime( time - ( 86400 * $delta )); 
             printf("%02d-%02d-%d", $t[3], $t[4]+1, $t[5]+1900); ' $1
}

wh=200
while [[ $wh -ge 0 ]] 
do
   echo $(ago $wh)             
   wh=$(( $wh - 1 ))
done

# 3  
Old 08-12-2009
display all dates 200 days back

Thanks for your response. when I executed the script i got this;

28-02-2010
27-02-2010
26-02-2010
25-02-2010
24-02-2010
23-02-2010
22-02-2010
21-02-2010
20-02-2010
19-02-2010
18-02-2010
17-02-2010
16-02-2010
15-02-2010
14-02-2010
13-02-2010
12-02-2010
11-02-2010
10-02-2010
09-02-2010
08-02-2010
07-02-2010
06-02-2010
05-02-2010
04-02-2010
03-02-2010
02-02-2010
01-02-2010
31-01-2010
30-01-2010
29-01-2010
28-01-2010
27-01-2010
26-01-2010
25-01-2010
24-01-2010
23-01-2010
22-01-2010
21-01-2010
20-01-2010
19-01-2010
18-01-2010
17-01-2010
16-01-2010
15-01-2010
14-01-2010
13-01-2010
12-01-2010
11-01-2010
10-01-2010
09-01-2010
08-01-2010
07-01-2010
06-01-2010
05-01-2010
04-01-2010
03-01-2010
02-01-2010
01-01-2010
31-12-2009
30-12-2009
29-12-2009
28-12-2009
27-12-2009
26-12-2009
25-12-2009
24-12-2009
23-12-2009
22-12-2009
21-12-2009
20-12-2009
19-12-2009
18-12-2009
17-12-2009
16-12-2009
15-12-2009
04-09-2009
03-09-2009
02-09-2009
01-09-2009
31-08-2009
30-08-2009
29-08-2009
28-08-2009
27-08-2009
26-08-2009
25-08-2009
24-08-2009
23-08-2009
22-08-2009
21-08-2009
20-08-2009
19-08-2009
18-08-2009
17-08-2009
16-08-2009
15-08-2009
14-08-2009
13-08-2009
12-08-2009

The output I was interested in was to display all the dates last 200 days starting from current date in the format such as 2009-08-11.

Thanks
Mark
# 4  
Old 08-12-2009
Change the printf statement
Code:
printf("%04d-%02d-02d", $t[5]+1900, $t[4+1, $t[4]);

# 5  
Old 08-13-2009
Just replace the %D date format with whatever date format you want.
Code:
#!/bin/ksh93

typeset -i daysago=200

((++daysago)); while ((--daysago))
do
   printf "%(%D)T\n" "$daysago days ago"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get number of days between 2 dates

Gents. Please can u help. I would like to calculate the days between two dates. Example file1 ( previous date) file1 - Input file 9/29/2010 10195 9/29/2010 1057 2/2/2016 10 2/2/2016 10169 2/2/2016 1057 2/3/2016 10005 2/3/2016 10014 In file2 I add the actual date using this code.... (9 Replies)
Discussion started by: jiam912
9 Replies

2. UNIX for Dummies Questions & Answers

How to display file whose size is between 100 to 200 kb ???

help me (1 Reply)
Discussion started by: sonu pandey
1 Replies

3. Shell Programming and Scripting

Display previous days dates in ksh

---------- Post updated at 03:42 AM ---------- Previous update was at 03:38 AM ---------- Sorry for a duplicate post, my post at the first place could not appear due to some net issue on my machine. Here is what i posted earlier: Hi, i am using ksh in Solaris, i wanted to assign today's,... (5 Replies)
Discussion started by: pr5439
5 Replies

4. UNIX for Advanced & Expert Users

How to get the sunday days between two dates?

Hi Am using Unix Ksh I have a two date input as DATE1=02/12/2012 DATE2=30/12/2012 I Need the output as only sunday date 02/12/2012 09/12/2012 16/12/2012 23/12/2012 30/12/2012 can anyone pls help me.. thanks in advance... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

5. Shell Programming and Scripting

days are between the two dates?

I have two times in the format of YYMMDD. Does anyone know an easy way in ksh for me to display how many days are between the two dates? Example1: X=101202 Y=101205 There are 3 days between X & Y Example2: X=101202 Y=111202 There are 365 days between X & Y Example3: X=101205... (3 Replies)
Discussion started by: oldman2
3 Replies

6. Shell Programming and Scripting

Get number of days between given dates

Hi I need one single command to get number of days between two given dates.datecalc is not working. ex. fromdate:01.04.2010 todate :24.04.2010 i should get the out put as 23 Thanks in advance (4 Replies)
Discussion started by: suryanarayana
4 Replies

7. UNIX for Dummies Questions & Answers

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (1 Reply)
Discussion started by: pavan_test
1 Replies

8. Shell Programming and Scripting

Days difference between two dates

Hello, I would like to find out the number of days between two dates of the format yyyy-mm-dd. Any help on this is highly appreciated. Thanks. (6 Replies)
Discussion started by: Data469
6 Replies

9. Shell Programming and Scripting

Difference between two dates in no of days ???

Hi All How to get the difference between two dates in no of days ??? My date format is like this YYYY/MM/DD. I have to get the no of days between two dates in the given format. I tried to search the forum but nothing came up similar to my requitement. Your help will be appreciated. ... (1 Reply)
Discussion started by: csaha
1 Replies

10. UNIX for Dummies Questions & Answers

days elapsed between 2 dates

does anybody know how to find out the number of days elapsed between 2 dates e.g. days elapsed between 020212 and 020110 (YYMMDD format) Thanking you in advance. Ravi. (1 Reply)
Discussion started by: rkkiran
1 Replies
Login or Register to Ask a Question