0

Hi all,

a=2007-05-10
b=2007-06-10

These are the two given dates and I need to compare.

The script should first compare years.If both are same or if a is lesser than b,it should print correct.If a is greater than b,then it should print error.Similarly for the dates(05 and 06).

No need to check for the months(10)

Regards
Dave Nithis

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by ghostdog74
0

are you using ksh or bash? if so

set -A aArray `print "$a" | sed -e 's/-/ /'`
set -A bArray `print "$b" | sed -e 's/-/ /'`
# now ${aArray[0]} and ${bArray[0]} contain the year
# and ${aArray[1]} and ${bArray[1]} contain the day
# and ${aArray[2]} and ${bArray[2]} contain the month

The comparison parts you can do yourself.

0

I am new to this shell scripting..
Can you give me the comparision part also

Regards
Dave Nithis

0

At the top of this forum is a fixed post to a tutorial. Read through some of that, try something out, if it doesn't work post your code and I'll help, but I'll not do it for you.

0
a="2007-05-10"
b="2007-06-10"
awk -v a="$a" -v b="$b" 'BEGIN{
n=split(a,tmpa,"-")
m=split(b,tmpb,"-")
if ( ( tmpa[1] <= tmpb[1] )  && ( tmpa[2] <= tmpb[2] ) ){
 print "correct"
}
else { print "not correct"}
}
'
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.