Need to validate a date input format

Hi all,

I have a shell script(K shell) which takes a date as input.

i want the input to be in DD-MM-YYYY format.

Can i enforce such a format of input string using just one line of code?

OR

do i need to parse the input date into different components and test them using Case statements separately?

Please. suggest an easy method of doing this.

Thanks a lot,
raju

One solution is to use my datecalc script.

If you do "datecalc -j yyyy mm dd" , datecalc will try to compute the modified julian day number of the date. This will fail if the date is not valid. You can simply test the return code:

if datecalc -j $year $month $day > /dev/null 2>&1  ; then
         echo date was valid
else
         echo date was invalid
fi

Here I sent stderr to /dev/null. But datecalc will write a specific error message to stderr if it detects an invalid date. You may want to just send the error on to the user.

Or you can can look at datecalc to see how to test the validity of a date. But it takes some code to this, mostly due to the complex rules involving leap year.

Hi guys, I'm new in UNIX and need to validate a date

How can I call datecalc script. from main shell?

is the same like to call another file with function, maybe

. ./datecalc_script.ksh

I tested it and dont run

thanks for your answers

grettings