Dear Perl Monks,

I am trying to write a script to get the date difference between the clearcase view created with the current date. I know that there is a module readily available in perl to get datediff but without using it, I want to write the script which will tell the view created in Years, Months and days. Please suggest.

@date = localtime(); $y = sprintf("%d %02d %02d\n",$date[5]+1900,$date[4]+1,$date[3]); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); $year += 1900; @MonthNames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec"); chomp($y); #print "\nToday's Date ----> $y"; #--------------------------------------------------------------------- +--------- # Timestamp / get actual date, check for environment, configuration fi +les #--------------------------------------------------------------------- +--------- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year += 1900; @date = localtime(); $year = sprintf("%s-%02d-%02d\n",$date[5]+1900,$date[4]+1,$date[3]); chomp($year); open(LOG, ">~veiwreport.txt") or die $!; #@vlist = "raghvens_test_view"; @vlist = `cleartool lsview -s`; foreach (@vlist) { chomp($_); #system "color 0A"; print "\nTag: $_"; print LOG "\nTag: $_"; @view_space = `cleartool space -view $_`; foreach $line (@view_space) { if ($line =~ m/is\s(.*)\sMb/) { #chomp($1); #$size=$1; #print " View-Size:$size Mb"; @size = split(/\s/,$line); #chomp($size[1]); print " Size : $size[7] Mb"; print LOG " Size : $size[7] Mb"; } } @view_details = `cleartool lsview -prop -full $_`; foreach $vd (@view_details) { if($vd =~ m/Last accessed/) { @arr = split(/\s+/,$vd); $accdate = $arr[2]; @acc = split(/T/,$accdate); chomp(@acc[0]); print "\tLast accessed : @acc[0]"; print LOG "\t Last accessed : @acc[0]"; } if ($vd =~ /Created/) { @a=split(".",$vd,1); #print "\nHellooooooo----> $a[0]"; @b=split("T",$a[0]); #@c=split("\w",$b[0]); $b[0] =~ s/(\w)*/ /; $b[0] =~ s/\s+//; print " created on $b[0]"; print LOG " created on $b[0]"; @c=split(/\-/,$b[0]); $d=@c[0]." ".@c[1]." ".@c[2]; #print "\nDate :: @c[2]"; #print "\nMonth:: @c[1]"; #print "\nYear :: @c[0]"; @ar=split("-",$d); $i=0; $i=sprintf("%2d",$i); foreach $month(@MonthNames) { $i++; if ($month eq $ar[1]) { $month=$i; if ($i <= 9) { $month= "0".$i; } $datee=$ar[2].$month.$ar[0]; #print "\nNEW DATE ::$datee \n"; } } #print "\n NEW DATE :: $datee \n"; $datee=$ar[2].$month.$ar[0]; #print"\n>>>>>>>>>>>>>>>$datee<<<<<<<<"; } } # print " >>>>>>>>>>>>> $d \n"; $d= sprintf("%s %02d %02d\n",$date[5]+1900,$date[4]+1,$date[3]); #print " \nView created on ----> $d \n"; @curt = $y; @crt = $b[0]; foreach(@curt) { @ncurt = (split/\s/,$_); foreach $nc (@ncurt) { # print "\n$nc"; } } foreach(@crt) { @ncrt = (split/\-/,$_); foreach $ncr (@ncrt) { #print "\n$ncr"; } } for($i=0;$i<=$#ncurt;$i++) { for($j=0;$j<=$#ncrt;$j++) { #print "\nValue of i is $i and j is $j"; $diffyr = $ncurt[0] - $ncrt[0]; #print "\nValue of i is $crt[1] and j is $curt[1]"; #print "\nYear difference is $diffyr \n"; $diffmon = $ncurt[1] - $ncrt[1]; if($diffmon < 0) { $diffmon =~ s/-//;} #print "\nMonth difference is $diffmon \n"; $diffdat = $ncurt[2] - $ncrt[2]; if($diffdat < 0) { $diffdat =~ s/-//;} #print "\nDate difference is $diffdat \n"; } } $diff = $diffyr." Yrs"." ".$diffmon." Months"." ".$diffdat." Days" +; # print "\nDifference between the dates: $diff \n"; print "\nAge: is $diff old \n"; print LOG "\nAge: is $diff old \n"; } close (LOG);

In reply to date difference by raghvens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.