regarding datevalidation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting regarding datevalidation
# 1  
Old 08-01-2008
Tools regarding datevalidation

Hi Perderabo,
i came across one of your script datecalc.ksh while i am searching for a script which validate the date.In tht i have a doubt at a particular part of code

could you please explain me wht this part of code signifies.i am new to unix shell scripting.

if ((!(year%100))); then
((!(year%400))) && leap=1
else
((!(year%4))) && leap=1
fi
feblength=28
((leap)) && feblength=29
print $feblength
return 0

Advanced thanks!!!!!

Thanks&Regards,:
Narasimharao.
# 2  
Old 08-01-2008
As you should be able to tell from the variable names, it handles leap years. % is the modulo operator (commonly called "remainder" in primary school). In other words, if the year is evenly divisible by 4 (modulo is zero, so the conditional (( (year % 4) )) returns false; we invert that value with the exclamation mark) but not by 100 except if it's also divisible by 400, it's a leap year, and so February will have 29 days.
# 3  
Old 08-01-2008
don't post questions in non technical forums! post moved to "shell scripting..." if you like to get in touch with members, just send a PM.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question