You can use the unix date tool to parse and validate it for you and verify the return code, for example.
Valid date, return code 0:
joel@bohr :~$ date -d "12/12/2000 13:00" Tue Dec 12 13:00:00 GMT 2000 joel@bohr :~$ echo $? 0
Invalid date, return code 1:
joel@bohr :~$ date -d "13/12/2000 13:00" date: invalid date `13/12/2000 13:00' joel@bohr :~$ echo $? 1
You can change the input format accepted by date using the + FORMAT parameter ( man date )
Putting it all together as a little script:
usrdate=$1 date -d "$usrdate" > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Date $usrdate was valid" else echo "Date $usrdate was invalid" fi
source share