Home » Infrastructure » Unix » Date Comparision
Date Comparision [message #207213] Mon, 04 December 2006 12:01 Go to next message
toshidas2000
Messages: 120
Registered: November 2005
Senior Member
All
I have a date in a file like 13-MAY-2006
I want this date to be compared with today's date and send me an email if the difference is 5 months. Any idea will be appreciated.

Thanks
Toshi Das
Re: Date Comparision [message #207222 is a reply to message #207213] Mon, 04 December 2006 13:26 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
I don't think it's practically feasible to do that type date arithmetic in shell commands. Try using perl or sililar. Example of date arithmetic.

#!/users/contrib/bin/perl
# Add or subtract days from the currect time

$days = $ARGV[0];
    
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
            = localtime(time() + $days * 24 * 60 * 60);
            
$mon++;           # Month is zero-based
$mon = (length($mon) < 2 ? "0" . $mon : $mon);
$mday = (length($mday) < 2 ? "0" . $mday : $mday);
$year = $year + 1900;
$hour = (length($hour) < 2 ? "0" . $hour : $hour);
$min = (length($min) < 2 ? "0" . $min : $min);
$sec = (length($sec) < 2 ? "0" . $sec : $sec);
$pm_date = "$mon/$mday/$year $hour:$min:$sec";

print "$pm_date\n";


dev>>date
Mon Dec  4 11:24:35 PST 2006
dev>>date_add.pl -10.5
11/23/2006 23:24:41
Re: Date Comparision [message #217029 is a reply to message #207213] Wed, 31 January 2007 07:00 Go to previous message
hemantpro
Messages: 1
Registered: January 2007
Junior Member
use Date::Manip perl module..
Previous Topic: HP-UX need help
Next Topic: .DEF file in HP-UX Shell scripting
Goto Forum:
  


Current Time: Mon Nov 25 02:37:10 CST 2024