<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: date less 7 days...help? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029263#M97670</link>
    <description>&lt;BR /&gt;Never invent your own wheel / date-math&lt;BR /&gt;&lt;BR /&gt;Never even invent your own usage of that math!&lt;BR /&gt;&lt;BR /&gt;It has all been done before. Just google.&lt;BR /&gt;I'm sur ethat in the minutes past someone will have replied with Clay's 'date hammer.&lt;BR /&gt;If not, goolge for: caljd.sh &lt;BR /&gt;&lt;BR /&gt;Here are two PERL code snippets I might use though. They both figure out the time in seconds, then subtract 7 days worth of seconds:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- show date math.pl ---&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my $day = 86400;&lt;BR /&gt;($y,$mo,$d) = unpack 'a4a2a2', shift;&lt;BR /&gt;$new_time = timelocal(0,0,0,$d,$mo - 1,$y - 1900) - 7*$day;&lt;BR /&gt;($s,$m,$h,$d,$m,$y)=localtime($new_time);&lt;BR /&gt;printf "%04d%02d%02d\n", $y+1900, $m+1, $d;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;--------------------- rename_to_week_ago.pl ----&lt;BR /&gt;&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my $day = 86400;&lt;BR /&gt;$_ = shift or die "Please provide a file to rename";&lt;BR /&gt;if (/(.*)\.(\d{4})(\d\d)(\d\d)$/) {&lt;BR /&gt;  $new_time = timelocal(0,0,0,$4,$3 - 1,$2 - 1900) - 7*$day;&lt;BR /&gt;  ($s,$m,$h,$d,$m,$y)=localtime($new_time);&lt;BR /&gt;  $new_name = sprintf "%s.%04d%02d%02d\n", $1, $y+1900, $m+1, $d;&lt;BR /&gt;  rename $_, $new_name;&lt;BR /&gt;} else {&lt;BR /&gt;  die "filespec not in xxx.yyyymmdd format";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 19 Feb 2007 15:29:58 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2007-02-19T15:29:58Z</dc:date>
    <item>
      <title>date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029258#M97665</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have to create a script that will name a file with the date - less 7 days.  So it should look like the following:&lt;BR /&gt;&lt;BR /&gt;file.20070219 -&amp;gt; file.20070212&lt;BR /&gt;&lt;BR /&gt;I guess this would get very tricky at the beginning of a month as the day and month would change.</description>
      <pubDate>Mon, 19 Feb 2007 14:50:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029258#M97665</guid>
      <dc:creator>Coolmar</dc:creator>
      <dc:date>2007-02-19T14:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029259#M97666</link>
      <description>No, it's actually pretty easy to get such a&lt;BR /&gt;string.  For example:&lt;BR /&gt;&lt;BR /&gt;alp $ write sys$output f$element( 0, " ", f$cvtime( "today-7-")) - "-" - "-"&lt;BR /&gt;20070212&lt;BR /&gt;&lt;BR /&gt;Or, for three weeks, to cross a month&lt;BR /&gt;boundary:&lt;BR /&gt;&lt;BR /&gt;alp $ write sys$output f$element( 0, " ", f$cvtime( "today-21-")) - "-" - "-"&lt;BR /&gt;20070129&lt;BR /&gt;&lt;BR /&gt;Oops.  Wrong operating system.  Never mind.</description>
      <pubDate>Mon, 19 Feb 2007 15:16:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029259#M97666</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-02-19T15:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029260#M97667</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Pass the yyyymmdd you need to this Perl snippet.  As written, you will be returned the date seven days ago:&lt;BR /&gt;&lt;BR /&gt;# perl -MDate::Calc=Add_Delta_Days -wle '($y,$m,$d)=unpack "A4A2A2",$ARGV[0];($ny,$nm,$nd)=Add_Delta_Days($y,$m,$d,-7);printf "%4d%02d%02d\n",$ny,$nm,$nd' 20070219&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Feb 2007 15:19:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029260#M97667</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-02-19T15:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029261#M97668</link>
      <description>Yeah, it gets tricky since dates have so many exceptions. Clay has created a great script to handle exactly this type of situation (attached).</description>
      <pubDate>Mon, 19 Feb 2007 15:22:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029261#M97668</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2007-02-19T15:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029262#M97669</link>
      <description>For almost any date question the answer is caljd.sh (or caljd.sl):&lt;BR /&gt;&lt;BR /&gt;DTMINUS7=$(caljd.sh -y -s $(caljd.sh -p 7))&lt;BR /&gt;echo "7 days ago was ${DTMINUS7}"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Invoke as caljd.sh -u for full usage and many examples.</description>
      <pubDate>Mon, 19 Feb 2007 15:24:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029262#M97669</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-02-19T15:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029263#M97670</link>
      <description>&lt;BR /&gt;Never invent your own wheel / date-math&lt;BR /&gt;&lt;BR /&gt;Never even invent your own usage of that math!&lt;BR /&gt;&lt;BR /&gt;It has all been done before. Just google.&lt;BR /&gt;I'm sur ethat in the minutes past someone will have replied with Clay's 'date hammer.&lt;BR /&gt;If not, goolge for: caljd.sh &lt;BR /&gt;&lt;BR /&gt;Here are two PERL code snippets I might use though. They both figure out the time in seconds, then subtract 7 days worth of seconds:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- show date math.pl ---&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my $day = 86400;&lt;BR /&gt;($y,$mo,$d) = unpack 'a4a2a2', shift;&lt;BR /&gt;$new_time = timelocal(0,0,0,$d,$mo - 1,$y - 1900) - 7*$day;&lt;BR /&gt;($s,$m,$h,$d,$m,$y)=localtime($new_time);&lt;BR /&gt;printf "%04d%02d%02d\n", $y+1900, $m+1, $d;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;--------------------- rename_to_week_ago.pl ----&lt;BR /&gt;&lt;BR /&gt;use Time::Local;&lt;BR /&gt;my $day = 86400;&lt;BR /&gt;$_ = shift or die "Please provide a file to rename";&lt;BR /&gt;if (/(.*)\.(\d{4})(\d\d)(\d\d)$/) {&lt;BR /&gt;  $new_time = timelocal(0,0,0,$4,$3 - 1,$2 - 1900) - 7*$day;&lt;BR /&gt;  ($s,$m,$h,$d,$m,$y)=localtime($new_time);&lt;BR /&gt;  $new_name = sprintf "%s.%04d%02d%02d\n", $1, $y+1900, $m+1, $d;&lt;BR /&gt;  rename $_, $new_name;&lt;BR /&gt;} else {&lt;BR /&gt;  die "filespec not in xxx.yyyymmdd format";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Feb 2007 15:29:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029263#M97670</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-02-19T15:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029264#M97671</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;By the way, given your filename format, simply use the shell parameter substitution to snip off the date to convert:&lt;BR /&gt;&lt;BR /&gt;# FILE=file.20070219;DATE=`echo ${FILE##*.}`&lt;BR /&gt;&lt;BR /&gt;...and then (from my first post) pass the ${DATE} thus derived to the Perl script as its argument:&lt;BR /&gt;&lt;BR /&gt;# perl -MDate::Calc=Add_Delta_Days -wle '($y,$m,$d)=unpack "A4A2A2",$ARGV[0];($ny,$nm,$nd)=Add_Delta_Days($y,$m,$d,-7);printf "%4d%02d%02d\n",$ny,$nm,$nd' ${DATE}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Feb 2007 15:34:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029264#M97671</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-02-19T15:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029265#M97672</link>
      <description>Coolmar,&lt;BR /&gt;get yourself gnu date !&lt;BR /&gt;date -d '1 week ago'&lt;BR /&gt;&lt;BR /&gt;For other examples see:&lt;BR /&gt;&lt;A href="http://www.faqs.org/faqs/hp/hpux-faq/section-168.html" target="_blank"&gt;http://www.faqs.org/faqs/hp/hpux-faq/section-168.html&lt;/A&gt;</description>
      <pubDate>Tue, 20 Feb 2007 03:41:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029265#M97672</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2007-02-20T03:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: date less 7 days...help?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029266#M97673</link>
      <description>Thanks everyone!</description>
      <pubDate>Tue, 20 Feb 2007 08:04:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/date-less-7-days-help/m-p/5029266#M97673</guid>
      <dc:creator>Coolmar</dc:creator>
      <dc:date>2007-02-20T08:04:56Z</dc:date>
    </item>
  </channel>
</rss>

