date -d "$date" +%Y-%m-%d
The latter is a format, -d allows you to enter an input date. If it is erroneous, it will return an error, which can be sent in bit by bit; if it is fixed, it will return the date.
Format modifiers can be found in the date man 1 date page man 1 date . Here is an example with an array of three dates:
dates=(2012-01-34 2014-01-01 2015-12-24) for Date in ${dates[@]} ; do if [ -z "$(date -d $Date 2>/dev/null)" ; then echo "Date $Date is invalid" else echo "Date $Date is valid" fi done
Just be careful: typing man date on Google, while some NSFW results may appear at work;)
runlevel0 Nov 21 '16 at 10:49 2016-11-21 10:49
source share