i am writing a generic script for the custom format date validation . here is the script
dateformat=$1
d=$2
date "+$dateformat" -d "$d" > /dev/null 2>&1
if [ $? != 0 ]
then
echo "Date $d NOT a valid YYYY-MM-DD date"
exit 1
fi
issue is
sh -x poc_col_val_date.sh "%Y-%m-%d" "2019-11-09"expected is valid date, output also correctsh -x poc_col_val_date.sh "%d-%m-%Y" "2019-11-09"expected is invalid date, output is valid date
+format string sets the output format. It doesn't affect input parsing. – muru May 11 '21 at 15:19busyboximplementation can do it I think, via its-Doption ex.busybox date -D "%d-%m-%Y" -d "2019-11-09"==>date: invalid date '2019-11-09'and an exit status of1– steeldriver May 11 '21 at 15:35