![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| simple issue.. | the_learner | UNIX for Advanced & Expert Users | 2 | 01-17-2008 04:44 PM |
| date issue-find prevoius date in a patricular format | bsandeep_80 | UNIX for Advanced & Expert Users | 3 | 11-15-2007 08:42 PM |
| simple scanf issue ? | the_learner | High Level Programming | 4 | 04-11-2007 04:51 AM |
| a simple way of converting a date in seconds to normal date | travian | HP-UX | 2 | 11-23-2006 12:25 PM |
| something simple, but i have no idea: a login issue | penguin-friend | UNIX for Dummies Questions & Answers | 2 | 03-31-2005 09:05 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Simple date issue
Hi all, i have used the search already before someone shouts at me and i have seen the 'datecalc' program but this is not working correctly for me in the shell and environment i am using. I am using solaris 10 and bourne shell. I have two dates '07-04-2009' and '05-05-2009'. I just need to know when the number of days exceeds 90 between two dates. Code:
i.e.
num_days='07-04-2009' - '05-05-2009'
if [ $num_days -gt 90 ]; then
do action....
fi
I can do it in Perl but this doesnt handle leap years etc: Code:
epoch()
{
perl -e '
use Time::Local;
$fmt = "%s"; # %s = seconds in epoch
$mday = substr("$ARGV[0]", 6, 2);
$mon = substr("$ARGV[0]", 4 ,2);
$year = substr("$ARGV[0]", 0 ,4);
$time = timelocal(0,0,0,$mday,$mon,$year);
print int $time;
' "$1"
}
date1=$( epoch '070709' );
date2=$( epoch '070809' );
diff=$(( $date1 - $date2 ))
if [[ $diff -gt 7776000 ] ; then
do action....
fi
Last edited by muay_tb; 05-05-2009 at 06:48 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|