Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the date from the past 30 days? 2

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to get the past 30 days dates in the following format ::--->

mm/dd/yy

I tried the function thats in the FAQ area. It works some what. But for some reason it doesn't go all the way back..

export TODAY=`GetDate 0 '+%m/%d/%y'`
export Day1=`GetDate -1 '+%m/%d/%y'`
export Day2=`GetDate -2 '+%m/%d/%y'`
.
.
export Day30=`GetDate -30 '+%m/%d/%y'`

Any idea's...........

Joe Despres
 
It may not have worked due to the footnote in that FAQ:

PHV said:
On some *nix flavor the authorized displacement is limited to +/-168 hours and thus the above "Next week" test fails.

I use perl with mktime() to do these kind of date calculations:

Code:
#!/usr/bin/perl

use POSIX;

$time_t = time();

for ($i=0; $i<=30; $i++) {
        print strftime "%m/%d/%Y\n",localtime $time_t;
        (undef,undef,undef,$mday,$mon,$year,undef,undef,undef) =
                localtime($time_t);
        $time_t = mktime( 0, 0, 0, --$mday, $mon, $year );
}

Annihilannic.
 
I need to the FAQ a bit closer next time...

Thanks!

Joe Despres
 

With a loop you could do:

Code:
for i in {30..0} ; do date +%D -d "$i days ago"; done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top