I want to validate the below date format in shell script 2015-Jul-13I'm using date -d 2015-Jul-13 +%Y-%b-%d but its giving error asdate: invalid date '2015-Jul-13'
Date validation in shell
shell script;date
GNU date does not support YYYY-MMM-DD. However, it does understand DD-MMM-YYYY. So if you really have to handle dates of this format you can do it with something like this, which simply swaps the arguments around to a format that date expects:ymd='2015-Jul-13'dmy=$(echo $ymd | awk -F- '{ OFS=FS; print $3,$2,$1 }')if date --date $dmy >/dev/null 2>&1then    echo OKfiHere's an all shell solution. Breaking it down, the IFS=- instructions tells the shell to split a forthcoming command line by hyphen - instead of whitespace. The set $ymd parses the $ymd variable as for a command line, but now splits by hyphen, assigning values to the parameters $1, $2 et seq. The echo $3-$2-$1 trivially outputs the three captured values in reversed order.ymd='2015-Jul-13'dmy=$(IFS=-; set $ymd; echo $3-$2-$1)if date --date $dmy >/dev/null 2>&1then    echo OKfi