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

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.

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

Regards
Dave Nithis

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.

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"}
}
'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.