Validate date format in a shell script

Use date

date "+%d/%m/%Y" -d "09/99/2013" > /dev/null  2>&1
 is_valid=$?

The date string must be in “MM/DD/YYYY” format.

If you do not get 0 then date is in invalid format.

Leave a Comment