How to get a 180days back date

  • Follow


Hi,

Stuck in the middle: as I have to calculate the date back to 180days
and remove the files for a particular directory.

So, please help me in this regards.

Server : E250 Ultra m/c with OS: Solaris 9
TZ=US/Eastern

I tried but failed to get the o/p:

BackDate=`$TZ+2160 date "%Y %m %d %h"`

Thanks in Advance!
Zubair
0
Reply mdzubair941 3/3/2004 3:54:40 PM

Zubair wrote:

> Stuck in the middle: as I have to calculate the date back to 180days

> I tried but failed to get the o/p:
> BackDate=`$TZ+2160 date "%Y %m %d %h"`

(csh/tcsh)
% env TZ=$TZ+4320 date
Friday September  5 16:12:43 Canada/Eastern 2003

(sh)
% TZ=$TZ+4320 date
Friday September  5 16:14:05 Canada/Eastern 2003

0
Reply Oscar 3/3/2004 4:15:34 PM


mdzubair941@indiatimes.com (Zubair) writes:
>Stuck in the middle: as I have to calculate the date back to 180days
>and remove the files for a particular directory.

>So, please help me in this regards.

By far, the easiest thing to do here is just to install GNU date
somewhere, and use its date string parsing functions. 

$ /usr/local/bin/date --date "180 days ago"
Fri Sep  5 10:18:08 CDT 2003
-- 
Doug McIntyre						merlyn@visi.com
                   Network Engineer/Jack of All Trades
                      Vector Internet Services, Inc.
1
Reply Doug 3/3/2004 4:19:02 PM

In article <c250b8$8e1$1@news.mie>,
Oscar del Rio  <delrio@mie.utoronto.ca> wrote:
>Zubair wrote:
>
>> Stuck in the middle: as I have to calculate the date back to 180days
>
>> I tried but failed to get the o/p:
>> BackDate=`$TZ+2160 date "%Y %m %d %h"`
>
>(csh/tcsh)
>% env TZ=$TZ+4320 date
>Friday September  5 16:12:43 Canada/Eastern 2003
>
>(sh)
>% TZ=$TZ+4320 date
>Friday September  5 16:14:05 Canada/Eastern 2003

This doesn't work in Solaris 9 (with current patches, anyway). The
offset is limited to 167:59:60 (i.e. one week) and if it is larger
the TZ variable is simply ignored.

Of course, there wasn't really ever any point in specifying
TZ=$TZ+4320 rather than, say, TZ=FooBar+4320. The offset is
always from UTC (GMT) with the name part just appearing at thn
timezone in the output.

Chris Thompson
Email: cet1 [at] cam.ac.uk
0
Reply cet1 3/3/2004 4:30:12 PM

mdzubair941@indiatimes.com (Zubair) writes:

> Stuck in the middle: as I have to calculate the date back to 180days
> and remove the files for a particular directory.

There are some possibilities in the comp.unix.shell FAQ at

http://home.comcast.net/~j.p.h/cus-faq.html#G

Look at subsection g.

Joe
-- 
Everyone in this room is wearing a uniform, and don't kid yourself.
   - Frank Zappa
0
Reply joe 3/3/2004 5:31:45 PM

mdzubair941@indiatimes.com (Zubair) wrote in message news:<db6ca1c6.0403030754.2d3ce961@posting.google.com>...
> Hi,
> 
> Stuck in the middle: as I have to calculate the date back to 180days
> and remove the files for a particular directory.
> 
> So, please help me in this regards.
> 

Try:

find /dirname/* -mtime +179

for all files modified 180 days or more ago. If you need files exactly
180 days ago, use this command for all files less than 180 days old:

find /dirname/* -mtime -181

and then use uniq to find files common to both find outputs. You may
have to tweak the values 179 and 181.
0
Reply shahswim 3/4/2004 9:00:05 PM

In article <b2e4e357.0403041300.5a463bf2@posting.google.com>,
swim learning <shahswim@yahoo.com> wrote:
>mdzubair941@indiatimes.com (Zubair) wrote in message news:<db6ca1c6.0403030754.2d3ce961@posting.google.com>...
>> Hi,
>> 
>> Stuck in the middle: as I have to calculate the date back to 180days
>> and remove the files for a particular directory.
>> 
>> So, please help me in this regards.
>> 
>
>Try:
>
>find /dirname/* -mtime +179
>
>for all files modified 180 days or more ago. If you need files exactly
>180 days ago, use this command for all files less than 180 days old:
>
>find /dirname/* -mtime -181
>
>and then use uniq to find files common to both find outputs. You may
>have to tweak the values 179 and 181.

find /dirname -mtime +179 -mtime -181

would be a great deal simpler, although with these particular numbers
that's in fact equivalent to

find /dirname -mtime 180

Chris Thompson
Email: cet1 [at] cam.ac.uk
0
Reply cet1 3/5/2004 12:33:49 AM

cet1@cus.cam.ac.uk (Chris Thompson) wrote in message news:<c28htd$t1s$1@pegasus.csx.cam.ac.uk>...
> In article <b2e4e357.0403041300.5a463bf2@posting.google.com>,
> swim learning <shahswim@yahoo.com> wrote:
> >mdzubair941@indiatimes.com (Zubair) wrote in message news:<db6ca1c6.0403030754.2d3ce961@posting.google.com>...
> >> Hi,
> >> 
> >> Stuck in the middle: as I have to calculate the date back to 180days
> >> and remove the files for a particular directory.
> >> 
> >> So, please help me in this regards.
> >> 
> >
> >Try:
> >
> >find /dirname/* -mtime +179
> >
> >for all files modified 180 days or more ago. If you need files exactly
> >180 days ago, use this command for all files less than 180 days old:
> >
> >find /dirname/* -mtime -181
> >
> >and then use uniq to find files common to both find outputs. You may
> >have to tweak the values 179 and 181.
> 
> find /dirname -mtime +179 -mtime -181
> 
> would be a great deal simpler, although with these particular numbers
> that's in fact equivalent to
> 
> find /dirname -mtime 180
> 
> Chris Thompson
> Email: cet1 [at] cam.ac.uk

Chris, your solution is more elegant. Especially if files modified
between two arbitrary dates are required. I did not know -mtime could
be used twice on the same find.
0
Reply shahswim 3/5/2004 5:18:34 PM

7 Replies
1140 Views

(page loaded in 0.138 seconds)

Similiar Articles:













7/22/2012 12:14:37 PM


Reply: