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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help Subtracting Dates 1

Status
Not open for further replies.
Aug 15, 2002
422
US
Hi there,

I need an EASY way to subtract the date by one day. The catch is that I need to watch a few things i.e:

If today was Oct. 1st:

Currently: I have a shell script that checks if $thisday - 1 creates Oct. 0. if 0 subtract one from the month and go to $last-day-of-month (Using a case statement).

What I would LIKE is to actually subtract the date:

Oct. 1 2002 - 1 = Sept. 30 2002

or Jan. 2003 - 1 = Dec. 31 2002

You know what I mean?

Any help would be greatly appreciated!!

Thanks!
-pd
 
I hope this helps; The calc_diff_time takes the date to compare against todays date in the format yyyymmdd;
This code is to generate the HTML tag for a new icon if the file's timestamp is less than 30 days old.


sub calc_diff_time {
my ($modtime) = @_;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
my $year1 = substr $modtime, 0,4;
my $mon1 = substr $modtime, 5, 2;
my $mday1 = substr $modtime, 7, 2;

$year = "20".substr $year, 1, 2;
if ($year==$year1) {
if (($yday - $yday1) < 300) {
$newimg = &quot;<img src=\&quot;new2.gif\&quot; alt=\&quot;item has been added in the last 30 days\&quot;>&quot;;
} else {
$newimg = &quot;1&quot;;
}
} elsif (($year-$year1)!=1) {
my $tmon = $mon;
$tmon+=12;
if (($tmon-$mon1)==1) {
$newimg=&quot;<img src=\&quot;new2.gif\&quot; alt=\&quot;item has been added in the last 30 days\&quot;>&quot;;
} else {
$newimg=&quot;&quot;;
}
} else {
$newimg=&quot;Slipped&quot;;
}
return $newimg;
}

sub format_time {
my ($time)=@_;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time);
$mon+=1;
if (length $hour == 1) {$hour= &quot;0&quot;.$hour;}
if (length $min == 1) {$min= &quot;0&quot;.$min;}
if (length $sec == 1) {$sec= &quot;0&quot;.$sec; }
if (length $mon == 1) {$mon= &quot;0&quot;.$mon;}

$year = &quot;20&quot;.substr $year, 1, 2;
return &quot;$year-$mon-$mday $hour:$min:$sec&quot;;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top